In my windows phone 8.1 application I have code like in ListBox template;
<StackPanel>
<ProgressBar x:Name="DownloadProgressBar" Maximum="100" Minimum="0" Value="25" HorizontalAlignment="Stretch" VerticalAlignment="Top" >
</ProgressBar>
</StackPanel>
Even if I am setting static values into control, when page loaded progress bars showing some arbitrary values (progress value). I have around 10 items in the list and all progress bars are showing some another values.
I am expecting that all progress bars should show 25%.
What's wrong in this logic?
Nothing wrong with your logic, put a
<Border BorderThickness="1" BorderBrush="Red">
<!-- rest of your template -->
</Border>
and you will realize what is going on.
You will see that each Item has a different width, thus making your Progress bar stretch to different width values.
To fix this you need to edit <ListBox> ItemContainerStyle's Style.
Related
I an new to windows app development,i searched for this but not found any where.I need the button at right edge and Stretch the textbox till buttons start.But I am unable to set the button to Right edge.
How to acheve this.
A stackpanel works like a container. If you define layout properties on your stackpanel, then the objects inside your stackpanel cannot be displayed outside of the stackpanel's limits.
For example :
If I set my row and column number in my stackpanel,
<StackPanel Grid.Row="0" Grid.Column="2" Name="Version" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top">
<Label Grid.Column="4" Grid.Row="6" Name="Ver" Content="V." HorizontalAlignment="Right" />
<TextBlock Name="Vers" Text="1.0" TextAlignment="Right" />
</StackPanel>
Then the row/column properties set on my label are ignored and the 'HorizontalAlignment="Right"' will place my label on the right side of the stackpanel, not the grid.
A solution may be to remove your button from your stackpanel, you are then free to place your button anywhere on the grid.
Another solution can be to expand your stackpanel's limits.
To do so, you can use the Grid.ColumnSpan property or simply set your stackpanel on the right of the grid.
Hope that helped.
Should the "dragger" on a scroll bar be increasing as I set the .MaximumValue property of the scroll bar to a smaller value?
I am using a wpf scroll bar.
Please let me know if you need anymore information.
Xaml:
<ScrollBar Grid.Row="0" HorizontalAlignment="Right" Name="scrollBar1" VerticalAlignment="Stretch" Width="18" Scroll="scrollBar1_Scroll" SmallChange="1" LargeChange="5" />
Code to set maxvalue:
scrollBarMaximum = numberOfRecords - numberOfRecordsToLoad;
I have a list box in WPF which displays the status of a number of worker threads. Included in the display is a progress bar.
It turns out that progress bars have an issue (defect?): the "Maximum" value is a dependency property, but the progress bar does not update when this property changes.
Somebody encounted a similar problem in this question. The suggested solution is to add a handler to the progress bar that deals with the dependency property changing.
But my progress bar is created by the WPF framework through a data template. (See code below) How could I attach a handler to these dynamically created progress bars?
Or, is there another way to solve this problem?
<DataTemplate x:Key="DataTemplateTransferWorker">
<Border Style="{StaticResource TransferWorker}" Height="Auto">
<StackPanel Orientation="Vertical">
<TextBlock Style="{StaticResource ItemHeader}">Transfer Worker</TextBlock>
<TextBlock Style="{StaticResource FieldValue}" Text="{Binding StatusDescription}" />
<!-- Note that the maximum comes from a changing property. -->
<ProgressBar
Margin="6, 3, 6, 3"
Height="12"
Orientation="Horizontal"
Background="Transparent"
Maximum="{Binding ServerJob.FileSize, Mode=OneWay}"
Value="{Binding BytesUploaded, Mode=OneWay}" />
Later Edit
It turns out that it's not as simple as the Maximum binding value being broken, because there are working examples where progress bars dynamically updates perfectly well.
It wasn't an INotifyPropertyChanged issue. I was notifying of any changes to the ServerJob property, (but not the ServerJob.FileSize property which is constant for each server job.) I also put a breakpoint on ServerJob.FileSize.get, and the framework was indeed querying the filesize in response to the property changed notification.
I also added two TextBlocks to the control, bound to ServerJob.FileSize and BytesUploaded respectively. And they updated exactly as they should.
But for some reason, as soon as the BytesUploaded value became non-zero the progress bar would zoom to 100%.
I've worked around the problem by adding a new property "PercentageComplete" which calculates the progress, and that way I can keep the maximum at a constant value of 100.
I tried creating an application with a ProgressBar in a DataTemplate whose Maximum is bound to a changing property. Like Greg Sansom i do not encounter any problem, i suppose you did not implement INotifyPropertyChanged in the class which contains the property you bound to, doing so should be the easiest solution to the problem.
I have a small custom control which downloads & displays a contacts image. It ensures that only 1 image is being downloaded at a time by adding itself to a static queue of images awaiting to be downloaded.
It is possible to get quite long contact lists. So I want it to only enter the download queue when it actually becomes visible on the screen (there's a default image).
I've tried placing the logic in the Loaded event, overriding OnRender and the IsVisibleChanged event, but none seem to give me what I want.
any suggestions?
D.R
Edit:
This is a WPF Application, sorry for not mentioning before...
Some system controls (like ListView) have property "VirtualMode" if you set it to true and handle RetrieveVirtualItem event. This event invokes for items which are visible currently and you have to fill those items with data(images) you want. So that you don't need to fill all items at once.
Have you considered using a PriorityBinding in order to provide that functionality?
<DataTemplate DataType="{x:Type vm:MyViewModel}">
<StackPanel Orientation="Horizontal">
<Image>
<Image.Source>
<PriorityBinding FallbackValue="{StaticResource ImgDownloading}">
<Binding Path="ImageSource" IsAsync="True" />
</PriorityBinding>
</Image.Source>
</Image>
<Label Content="{Binding Name}" />
</StackPanel>
</DataTemplate>
Below is the XAML code i have for a Bing Maps Silverlight weather related implementation.
Here is what i am trying to do:
Have a bing maps with several (over 100) pushpins- on mouseover - show a contentpopup (canvas=myPopup) below. Simple enough.
Everything works fine - however, when mypopup displays on mouseover, it is not on the foreground (the other pins appear on top of the contentpopup) - hence making it not very readable.
Question:
How do i specifiy the myPopup canvas specified in XAML below to always appear in the foreground, i.e. top most of the Bing Maps silverlight control when a user views it on mouseover.
Thanks!
<Grid x:Name="LayoutRoot" Background="White">
<m:Map x:Name="GlobalMap" Mode="Road" Center="15,7" ZoomLevel="2" CredentialsProvider="{StaticResource MyCredentials}" Margin="-70,-40,-100,-72">
<m:MapLayer x:Name="myLayer">
<Canvas x:Name="myPopup" Visibility="Collapsed" Opacity="1">
<Rectangle x:Name="myPopupRectangle" Fill="White" Canvas.Left="0" Canvas.Top="0" Height="100"
Width="100" RadiusX="15" RadiusY="15"/>
<StackPanel Canvas.Left="8" Canvas.Top="8">
<TextBlock x:Name="myPopupTexts" FontSize="5" Width="100">
</TextBlock>
</StackPanel>
</Canvas>
</m:MapLayer>
</m:Map>
</Grid>
Try adding Canvas.ZIndex to the MapLayer element, give it a large value like 200 or add your push pins to another MapLayer (rather than adding the pins directly to the map) that appears ahead of this popup layer in document order.
I did something similar to this, but took a different approach. What I did was create a custom pushpin template and create a PopUp within the template.
When the user hovers over the pushpin, the popup is displayed. Using the PopUp will solve your problem, since the control will automatically position it on top of everything. Try wrapping the Canvas in a PopPup and see if that works.
hth