I have a DataTemplate which describes the Items of a ListBox in XAML. Into each Item I have four things:
1) a progress bar
2) three buttons
I noticed that when the progress bar is advancing, the buttons result to be unclickable, why?
There is my XAML code referring to the abovementioned ListBox:
<ListBox Grid.Column="1" Name="TransfersList" Margin="30,10,-0.444,34.889" ItemsSource="{Binding DataTx}"
SelectionChanged="TransfersList_SelectionChanged" Grid.Row="1" Grid.ColumnSpan="3"
HorizontalContentAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<ProgressBar Height="20" Minimum="0" Maximum="{Binding NChunks}" Name="gasparino_il_carbonaro"
Value="{Binding PbStatus}" Foreground="{Binding Color}"
ToolTip="{Binding TooltipInfo}" />
<Button Content="Delete all" Grid.Column="3" Margin="0,0,0,0" Grid.Row="1" Height="20"
VerticalAlignment="Center" HorizontalAlignment="Left" Width="75" Background="White"
Click="DeleteAllTransfersClick" />
<Button Content="Stop all" Grid.Column="3" Margin="0,0,0,0" Grid.Row="1" Height="20"
VerticalAlignment="Center" HorizontalAlignment="Center" Width="75" Background="White"
Click="StopAllTransfersClick" />
<Button Content="Resume all" Grid.Column="3" Margin="0,0,0,0" Grid.Row="1" Height="20"
VerticalAlignment="Center" HorizontalAlignment="Right" Width="75" Background="White"
Click="ResumeAllTransfersClick" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
It happens in Single threaded application. To use multi threaded concept, show progress bar using using event & delegates.
Related
I'm trying to align below controls horizontally by keeping the label and the combobox on the left and both buttons on the right. I've tried different approaches using StackPanel but nothing gives me the desired output. Appreciate if you guys could point out what am I doing wrong here?
Current Layout
XAML source
<StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Center" Orientation="Vertical" Margin="0,0,0,2" >
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal" VerticalAlignment="Center">
<Label Content="Age Bucket" HorizontalAlignment="Left" VerticalAlignment="Center" />
<ComboBox HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10,0,0,0" Width="100"
SelectedValue="{Binding SelectedAgeBucket}"
DisplayMemberPath="DisplayMember" SelectedValuePath="ValueMember"
ItemsSource="{Binding AgeBuckets}" IsSynchronizedWithCurrentItem="True"/>
</StackPanel>
<StackPanel HorizontalAlignment="Right" VerticalAlignment="Center" Orientation="Horizontal" Margin="0,0,0,2">
<Button Click="Button_Click_1" Content="Export" HorizontalAlignment="Right" />
<Button HorizontalAlignment="Right" VerticalAlignment="Center" Click="Button_Click_2" Content="Print" Margin="5,0" />
</StackPanel>
</StackPanel>
<telerik:RadDataPager x:Name="radDataPager" Source="{Binding Items, ElementName=grdDetails}" PageSize="100" />
</StackPanel>
How can I create a multicolumn ListView/ListBox in WPF with good performance. I know how to do it with WrapPanel. In the ListBox I have about 70-150 items and scrolling is laggy/not so fluent (like with VirtualStackPanel). Do you know how to solve this problem?
Thank you
Here is ListBox XAML
<ListBox x:Name="ListBoxSubtitles" VirtualizingStackPanel.IsVirtualizing="True" Margin="0,0,0,0" ItemsSource="{Binding Subtitle,Mode=TwoWay}" Grid.Row="1" ScrollViewer.HorizontalScrollBarVisibility="Disabled" BorderBrush="{x:Null}" Background="#FFEEECEC"
>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Width="520" Height="150" Background="#FF424242" Margin="5,5,5,0">
<Grid.RowDefinitions>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="85"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Source="{Binding PosterImgUri,Mode=TwoWay}" Grid.ColumnSpan="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Stretch="UniformToFill">
<Image.Effect>
<BlurEffect Radius="40" />
</Image.Effect>
</Image>
<Image Width="75" Height="110" Grid.Column="0" Margin="2,2,2,2" VerticalAlignment="Top" HorizontalAlignment="Stretch" Source="{Binding PosterImgUri,Mode=TwoWay}" Stretch="Fill"/>
<Label Grid.Column="0" Content="86%" HorizontalAlignment="Center" Margin="0,0,0,0" VerticalAlignment="Bottom" Background="{x:Null}" Foreground="White" FontFamily="Segoe UI Semibold" FontSize="18" FontWeight="Bold"/>
<StackPanel Grid.Column="1">
<Label HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top" Background="{x:Null}" Foreground="White" FontFamily="Segoe UI Semibold" FontSize="25" FontWeight="Bold">
<TextBlock TextWrapping="Wrap" Text="{Binding SubtitleName,Mode=TwoWay}">
</TextBlock>
</Label>
<Grid>
<Label Content="Stažení:" HorizontalAlignment="Left" Margin="0,-7,0,0" VerticalAlignment="Top" Background="{x:Null}" Foreground="White" FontFamily="Segoe UI Light" FontSize="18"/>
<Label Content="{Binding subtitleName,Mode=TwoWay}" HorizontalAlignment="Left" Margin="65,-7,0,0" VerticalAlignment="Top" Background="{x:Null}" Foreground="White" FontFamily="Segoe UI Light" FontSize="18"/>
</Grid>
<Grid Width="100" Height="20" Margin="0,0,0,0" HorizontalAlignment="Left">
<ProgressBar Value="50" HorizontalAlignment="Stretch" VerticalContentAlignment="Stretch" Margin="7,0,0,0" Foreground="#FF84E60F" Background="White"/>
<Label Margin="0,-2,0,0" HorizontalAlignment="Center" VerticalAlignment="Center" Content="50" FontSize="10" FontWeight="Bold"></Label>
</Grid>
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
also I would like to ask, how to remove this blue selection when mouse is focusing item.
You need a virtualizing wrap panel. Unfortunately, writing such kind of panel is not easy and most good implementations are either not free or not working for arbitrary complex data templates.
You can make the image bindings async, using the IsAsync property.
Another approach is to reduce the visual tree, which is not an option, because you go after quality. You can move the layout from the DataTemplate into a dedicated UserControl and load the images only when the control is visible (VisibilityChanged event or rectangle intersect based).
I have 2 textblocks on my form. I need to have vertical scrollbars in each of them. Due to some reason, I am not able to get the scrollbars on both. Kindly provide me with some idea.
<Grid>
<Button Content="COMPARE" HorizontalAlignment="Left" Margin="216,30,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
<TextBox x:Name="TextBox1" ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Auto" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,69,0,0" TextWrapping="Wrap" RenderTransformOrigin="-1.351,-2.164" Height="242" Width="226" Loaded="TextBox1_Loaded" />
<ScrollViewer>
<TextBlock x:Name="TextBlock1" HorizontalAlignment="Left" Margin="10,69,0,0" TextWrapping="Wrap" VerticalAlignment="Top" RenderTransformOrigin="-1.351,-2.164" Height="242" Width="226" Loaded="TextBlock1_Loaded" />
</ScrollViewer>
<TextBox x:Name="TextBox2" ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Auto" HorizontalAlignment="Left" Margin="258,69,0,0" TextWrapping="Wrap" VerticalAlignment="Top" RenderTransformOrigin="-1.351,-2.164" Height="242" Width="226" Loaded="TextBox2_Loaded"/>
<ScrollViewer>
<TextBlock x:Name="TextBlock2" HorizontalAlignment="Left" Margin="258,69,0,0" TextWrapping="Wrap" VerticalAlignment="Top" RenderTransformOrigin="-1.351,-2.164" Height="242" Width="226" Loaded="TextBlock2_Loaded_1"/>
</ScrollViewer>
<Button Content="EDIT" HorizontalAlignment="Left" Margin="409,30,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click_1"/>
<Button Content="HOME" HorizontalAlignment="Left" Margin="21,26,0,0" VerticalAlignment="Top" Width="75" RenderTransformOrigin="0.23,0.986" Click="Button_Click_2"/>
</Grid>
Try to check this out:
1. XAML Code:
<ScrollViewer Grid.Column="0" Grid.Row="0">
<TextBlock x:Name="ATextBlock" ></TextBlock></ScrollViewer>
<ScrollViewer Grid.Row="0" Grid.Column="1" >
<TextBlock x:Name="BtTextBlock" ></TextBlock></ScrollViewer>
the problem was; the Height definition on the TextBlock. Just remove it and that is.
regards.,
To show vertical scroll bar on a TextBox when needed you can use this XAML
<TextBox .... VerticalScrollBarVisibility="Auto" />
ScrollBar will apear when text does not fit the original space given to controll.
I noticed my application is using about 15% of the CPU constantly when I have a ListBox visible.
I tried using Redgate's ANTS Performance Profiler but I did not manage to find the origin of this CPU-usage. Nothing is being updated so I think this is very strange.
Here is the XAML-code for the ListBox:
<ListBox x:Name="MusicList" ItemsSource="{Binding}" MouseDoubleClick="MusicList_MouseDoubleClick" PreviewMouseWheel="MusicList_PreviewMouseWheel" PreviewMouseLeftButtonDown="MusicList_PreviewMouseLeftButtonDown" TextSearch.TextPath="name" KeyDown="MusicList_KeyDown" Background="#3F181818" Margin="0,175,0,0" BorderThickness="0,1,0,0" ScrollViewer.HorizontalScrollBarVisibility="Hidden" BorderBrush="#FF282828">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="88">
<Border Height="64" Width="64" Margin="12,12,0,12">
<Image Stretch="UniformToFill" Source="{Binding Path=album.albumart, IsAsync=True}"/>
</Border>
<StackPanel Orientation="Vertical" VerticalAlignment="Top" Margin="0,10,0,0">
<TextBlock Text="{Binding Path=name, IsAsync=True, Mode=OneTime}"
Margin="10,0,0,0" Width="300" Height="40"
TextTrimming="WordEllipsis" TextWrapping="Wrap"
FontSize="16" HorizontalAlignment="Left"
Foreground="White"/>
<TextBlock Text="{Binding Path=album.name, IsAsync=True, Mode=OneTime}"
Margin="10,-15,0,0" Width="300" Height="20"
TextTrimming="WordEllipsis"
HorizontalAlignment="Left"
FontSize="14" Opacity="0.49" Foreground="White"/>
<TextBlock Text="{Binding Path=artistname, IsAsync=True, Mode=OneTime}"
Margin="10,2,0,0" Width="300"
TextTrimming="WordEllipsis"
HorizontalAlignment="Left"
FontSize="12" Opacity="0.49" Foreground="White"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I do have about 500 items in the listbox itself, but I assume DataViritualization is on, since scrolling makes it look like new items are being drawed.
Does anyone know why this is happening?
i design page bellow code.
<ScrollViewer VerticalScrollBarVisibility="Visible" Grid.Row="1" x:Name="svProduct">
<StackPanel>
<ItemsControl x:Name="lstSearchResult" ItemsSource="{Binding Path=PIProductList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Width="480" Style="{Binding CellStyle}" Orientation="Horizontal" VerticalAlignment="Center" Height="50" >
<TextBlock Foreground="Black" FontSize="20" Width="320" FontFamily="Tahoma" Margin="10,0,0,0" Text="{Binding Title}" VerticalAlignment="Center" TextWrapping="Wrap"></TextBlock>
<Button Name="btnBookmark" Click="btnBookmark_Click" Tag="{Binding}" Background="Transparent">
<Button.Content>
<Image Source="/Images/bookmarks_red.png" Width="33" Height="30" VerticalAlignment="Top" Margin="-15"></Image>
</Button.Content>
</Button>
<Button BorderThickness="0" x:Name="btnSubmit" Click="btnSubmit_Click" Background="Transparent" Tag="{Binding}" >
<Button.Content>
<Image Name="ram" Source="/Images/blue_arrow.png" Width="40" Height="40" VerticalAlignment="Top" Margin="-15"></Image>
</Button.Content>
</Button>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</ScrollViewer>
i want to access for btnBookmark visuble false .
can't access btnBookmark.Visibility=Visibility.collapsed
how to do this?
please help to me...........
The best way I know to do this is to create a Visiblity property on your item ViewModel (the one that is bound to each row in your ItemsControl) and toggle that value based on the changes to each item, presumably via the toggle button in each row. I don't know of a good way to "loop and look" for these internal controls. You're much better off using the existing data binding infrastructure to manage this for you.