I have a DataGrid which has its RowDetailsTemplate set to a ListBox. I have set the DataGridRowHeaderStyle as a ToggleButton as below:
<Style x:Key="DataGridRowHeaderStyle" TargetType="{x:Type DataGridRowHeader}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="36"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border x:Name="bd" BorderBrush="Black" BorderThickness="1,0.5,1,1" Height="36" Width="20" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" Margin="0" >
<ToggleButton Style="{StaticResource RowDetailExpanderWithPlusSymbol}"
Visibility="{Binding Converter={StaticResource RowDetailsVisibilityConverter}}"
Click="ToggleButton_Click"
MouseDoubleClick="ToggleButton_MouseDoubleClick">
<!--<ToggleButton.CommandParameter>
<MultiBinding Converter="{StaticResource SelectedCodesMultiBindingConverter}">
<Binding Path="."/>
<Binding RelativeSource="{RelativeSource Self}" Path="IsChecked"/>
</MultiBinding>
</ToggleButton.CommandParameter>-->
<ToggleButton.IsChecked>
<Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type DataGridRow}}" Path="DetailsVisibility" Mode="TwoWay" >
<Binding.Converter>
<infConv:DetailsVisibilityToBool FalseToVisibility="Collapsed" />
</Binding.Converter>
</Binding>
</ToggleButton.IsChecked>
</ToggleButton>
</Border>
<Border Grid.Row="1" VerticalAlignment="Stretch"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I am selecting the DataGridRow when I click the DataGridRowHeader toggle button as below:
private void ToggleButton_Click(object sender, RoutedEventArgs e)
{
try
{
ToggleButton tg = sender as ToggleButton;
UiUser user = tg.DataContext as UiUser;
DataGridRow dr = dg.ItemContainerGenerator.ContainerFromItem(user) as DataGridRow;
dr.IsSelected = true;
dr.Focus();
}
catch (Exception ex)
{
}
}
What I want is that the next time I select the ListBox item it should be selected and be active. However I have to click it two times to get make it active. Kindly Help.
EDIT - RowDetailsTemplate:
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<ContentControl DataContext="{Binding}">
<ListBox x:Name="lBox" ItemsSource="{Binding Similar}">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Blue"/>
<!-- Background of selected item when focussed -->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Blue"/>
<!-- Background of selected item when not focussed -->
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="LightGray" />
</Style.Resources>
<!--<EventSetter Event="PreviewMouseDown" Handler="lBoxItem_PreviewMouseDown"/>-->
<EventSetter Event="MouseDoubleClick" Handler="LBox_MouseDoubleClick_Inside"/>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Blue"/>
</Trigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" >
<Border Margin="-3,-3,0,0" BorderBrush="Gray" Width="{Binding ElementName=NameDataGridColumn, Path=ActualWidth}" BorderThickness="1,0,0,1">
<TextBlock ToolTip="{Binding person, Converter={StaticResource FormattedNameConverter}}" Margin="5,0,0,0" TextTrimming="CharacterEllipsis"
Text="{Binding InternalUser.person, Converter={StaticResource FormattedNameConverter}}" VerticalAlignment="Center">
</TextBlock>
</Border>
<Border Margin="0,0,0,0" BorderBrush="Gray" Width="{Binding ElementName=OrgDataGridColumn, Path=ActualWidth}" BorderThickness="1,0,0,1">
<TextBlock HorizontalAlignment="Stretch" TextTrimming="CharacterEllipsis" ToolTip="{Binding Path=organizationsString}"
Text="{Binding Path=organizationsString}"
Margin="5,0,0,0" VerticalAlignment="Center"/>
</Border>
<Border Margin="0,0,0,0" BorderBrush="Gray" Width="{Binding ElementName=RolesDataGridColumn, Path=ActualWidth}" BorderThickness="1,0,0,1">
<TextBlock HorizontalAlignment="Stretch" Margin="5,0,0,0"
Text="{Binding Path=rolesString}" ToolTip="{Binding Path=rolesString}"
TextTrimming="CharacterEllipsis" VerticalAlignment="Center"
ToolTipService.Placement="Bottom" />
</Border>
<Border Margin="0,0,0,0" BorderBrush="Gray" Width="{Binding ElementName=NPIDDataGridColumn, Path=ActualWidth}" BorderThickness="1,0,0,1">
<TextBlock HorizontalAlignment="Stretch"
Text="{Binding InternalUser.npid}" ToolTip="{Binding InternalUser.npid}" TextTrimming="CharacterEllipsis" Margin="5,0,0,0" VerticalAlignment="Center"/>
</Border>
<Border Margin="0,0,0,0" BorderBrush="Gray" Width="{Binding ElementName=EmailDataGridColumn, Path=ActualWidth}" BorderThickness="1,0,0,1">
<TextBlock Text="{Binding InternalUser.principal.user_name}" ToolTip="{Binding InternalUser.principal.user_name}" VerticalAlignment="Center" TextTrimming="CharacterEllipsis"/>
</Border>
<Border Margin="0,0,0,0" BorderBrush="Gray" Width="{Binding ElementName=Status, Path=ActualWidth}" BorderThickness="1,0,0,1">
<TextBlock Text="{Binding ActiveStatus}" ToolTip="{Binding ActiveStatus}" Padding="4,0,0,0" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" />
</Border>
<Border Margin="0,0,0,0" BorderBrush="Gray" Width="{Binding ElementName=DMUserName, Path=ActualWidth}" BorderThickness="1,0,0,1">
<TextBlock Text="{Binding InternalUser.directMailAccountId}"
VerticalAlignment="Center" TextTrimming="CharacterEllipsis"
ToolTip="{Binding InternalUser.directMailAccountId}"/>
</Border>
<Border Margin="0,0,0,0" BorderBrush="Gray" Width="{Binding ElementName=DMAccountStatus, Path=ActualWidth}" BorderThickness="1,0,0,1">
<TextBlock Margin="5,0,0,0" Text="{Binding DMStatus}"
HorizontalAlignment="Stretch" VerticalAlignment="Center" TextTrimming="CharacterEllipsis"
ToolTip="{Binding DMStatus}"/>
</Border>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ContentControl>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
I had the same problem: There is a DataGrid, and each row has a RowDetails - RowDetailsTemplate consists of two ListBoxes. ListBoxItem is a ToggleButton. So, I wanted to select toggle button by the first click.
First I founded this http://wpf.codeplex.com/wikipage?title=Single-Click%20Editing .
so, I updated my ListBox`s style
<Style x:Key="MyListBoxStyle" BasedOn="{StaticResource ToggleButtonListBoxStyle}" TargetType="{x:Type ListBox}">
<Setter Property="ItemContainerStyle">
<Setter.Value>
<Style TargetType="{x:Type ListBoxItem}">
<EventSetter Event="PreviewMouseLeftButtonDown" Handler="ListBoxItem_PreviewMouseLeftButtonDown"></EventSetter>
</Style>
</Setter.Value>
</Setter>
And in CodeBehind :
private void ListBoxItem_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
var item = sender as ListBoxItem;
if (item != null)
{
var toggleButton = WpfUiHelper.FindVisualChild<ToggleButton>(item);
if (toggleButton != null)
{
if (toggleButton.IsChecked == false) toggleButton.IsChecked = true;
else toggleButton.IsChecked = false;
e.Handled = true;
}
}
}
And now when I clicks at toggle button in RowDetails for the fitst time - it selects or deselects.
Hope it will help.
Related
In my example, I have a list box (CommentsList). Every item in the list has another inner list ( repliesList). When I have have some commens the vertical scroll bar is shown but when I have a comment with a list or replays the Vertical Scroll bar is not shown.
Here you have the xaml design, could you please tell me where is the error?
CommentsPanel.xaml:
<DockPanel LastChildFill="True" HorizontalAlignment="Stretch" VerticalAlignment="Top">
<TextBlock DockPanel.Dock="Bottom" TextWrapping="Wrap" Visibility="{Binding HasComments, Converter={StaticResource reversedBooleanToVisibilityConverter}}" Text="There are no comments on this row." x:Name="NoCommentsLabel"/>
<TextBlock DockPanel.Dock="Bottom" TextWrapping="Wrap" Text="Use Previous and Next to navigate throught all comments." x:Name="NoCommentsOpenDiagramsLabel">
<TextBlock.Visibility>
<MultiBinding Converter="{StaticResource multiBooleanToVisibilityConverter}">
<Binding Path="HasComments"/>
<Binding Path="CommentsOnOpenDiagrams" />
</MultiBinding>
</TextBlock.Visibility>
</TextBlock>
<ListBox DockPanel.Dock="Bottom" x:Name="CommentsList" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemsSource="{Binding Path=CommentsListItems.View}"
HorizontalContentAlignment="Stretch" BorderThickness="0" Background="Transparent" SelectionMode="Single" SelectionChanged="CommentsList_OnSelectionChanged"
Width="{Binding Width, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}, AncestorLevel=1}}">
<ListBox.ItemTemplate>
<DataTemplate>
<wpfControlLibrary:CommentThread Margin="2,2,5,5" IsSelected="{Binding Path=IsSelected, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}}, UpdateSourceTrigger=PropertyChanged}"
Width="{Binding Width, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}, AncestorLevel=1}}">
</wpfControlLibrary:CommentThread>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DockPanel>
wpfControlLibrary:CommentThread :
<Border x:Name="borderMain" BorderBrush="Transparent" BorderThickness="1" Background="#00000000" Padding="3">
<Grid x:Name="commentGrid">
<Grid x:Name="threadGrid" Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*"/>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ContentPresenter Grid.Row="0" Grid.Column="0" Content="{Binding Path=CommentModel}">
<ContentPresenter.Style>
<Style TargetType="ContentPresenter">
<Setter Property="ContentTemplate" Value="{StaticResource NoLyncTemplate}" />
</Style>
</ContentPresenter.Style>
</ContentPresenter>
**<ListBox Margin="50, 0, 0 0" Grid.Row="1" x:Name="repliesList" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemContainerStyle="{StaticResource ContainerStyle}" HorizontalContentAlignment="Stretch" SelectionChanged="RepliesList_OnSelectionChanged" BorderThickness="0" Background="Transparent" SelectionMode="Single" Grid.Column="0" Grid.ColumnSpan="2" Width="{Binding Width, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}, AncestorLevel=1}}" ItemsSource="{Binding Path=CommentRepliesListItems.View}"**
>
<Grid Grid.Row="3" Margin="50,0,0,0" >
<TextBlock x:Name="watermark_TextBlock" Text="Reply..." Foreground="{StaticResource brushWatermarkForeground}" Background="{StaticResource brushWatermarkBackground}"
Width="{Binding ActualWidth, ElementName=threadGrid, Mode=OneWay}" HorizontalAlignment="Left" MouseLeftButtonUp="Watermark_OnMouseLeftButtonUp" KeyUp="Watermark_KeyUp">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True"></Condition>
<Condition Property="Visibility" Value="Visible"></Condition>
</MultiTrigger.Conditions>
<Setter Property="Cursor" Value="IBeam"></Setter>
</MultiTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
<TextBox x:Name="replyBox" Text="" Visibility="Collapsed" HorizontalAlignment="Stretch" TextWrapping="Wrap" VerticalAlignment="Top" Height="40"
VerticalScrollBarVisibility="Auto" LostFocus="CommentEdit_OnLostFocus"
KeyUp="ReplyBox_OnKeyUp"
/>
</Grid>
</Grid>
</Grid>
</Border>
The solution is use physical scrolling instead of logical scrolling in the listbox:
ScrollViewer.CanContentScroll="False"
We have a WPF windows application, We need to change the Modal dialog title bar color, Below is the code snippet and also the screenshot of current dialog box. We are using WPF DevExpress.Xpf third party dlls.
We have tried background color change option also at various places but nothing works and title bar colro wont get changed.
<coreClient:BaseWindow x:Name="ModalDialogWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
ShowInTaskbar="False"
Height="10" Width="10"
Activated="ModalDialogWindowActivated"
Icon="/Images/app_icon_small.png"
Title="{Binding Path=DialogTitle}">
<coreClient:BaseWindow.Resources>
<converter:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
<converter:EmptyStringToVisibilityConverter x:Key="EmptyStringToVisibilityConverter" />
<converter:ModalDialogActionCommandArgsConverter x:Key="ModalDialogActionCommandArgsConverter" />
</coreClient:BaseWindow.Resources>
<DockPanel LastChildFill="True">
<Border Height="35" DockPanel.Dock="Bottom" Margin="0" Style="{StaticResource BdrModalDialogActionPanel}">
<DockPanel LastChildFill="True">
<StackPanel x:Name="actionButtonPanel"
Orientation="Horizontal"
DockPanel.Dock="Right"
HorizontalAlignment="Right"
VerticalAlignment="Center">
<ItemsControl Name="actionButtons"
ItemsSource="{Binding ActionButtons}"
HorizontalAlignment="Right"
Focusable="False"
VerticalAlignment="Center">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button x:Name="additionalActionButton"
IsDefault="{Binding IsButtonDefault}"
IsCancel="{Binding IsButtonCancel}"
IsEnabled="{Binding IsButtonEnabled}"
Content="{Binding Path=Content}"
HorizontalAlignment="Center" VerticalAlignment="Center"
Margin="0,0,5,0"
ToolTipService.ShowOnDisabled="True"
Command="{Binding Path=ActionCommand}" Height="29">
<Button.CommandParameter>
<MultiBinding Converter="{StaticResource ModalDialogActionCommandArgsConverter}">
<MultiBinding.Bindings>
<Binding ElementName="ModalDialogWindow" />
<Binding />
</MultiBinding.Bindings>
</MultiBinding>
</Button.CommandParameter>
<Button.Style>
<Style TargetType="{x:Type Button}">
<Style.Triggers>
<Trigger Property="Content" Value="Search">
<Setter Property="Foreground" Value="White"/>
<Setter Property="Height" Value="29" />
<Setter Property="Width" Value="76" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid Background="#0096d6" x:Name="RootElement">
<TextBlock Text="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
<Button.ToolTip>
<ToolTip Visibility="{Binding TooltipText, Converter={StaticResource EmptyStringToVisibilityConverter}, ConverterParameter='HIDDEN'}"
Content="{Binding TooltipText}" />
</Button.ToolTip>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
<StackPanel Orientation="Horizontal"
DockPanel.Dock="Left"
Visibility="{Binding IsActionInProgress, Converter={StaticResource BoolToVisibilityConverter}}">
<common:SpinnerControl x:Name="SpinnerControl" VerticalAlignment="Center" VerticalContentAlignment="Center" />
<TextBlock Text="{Binding ActionStatusMessage}"
Margin="5,0,0,0"
VerticalAlignment="Center"/>
</StackPanel>
</DockPanel>
</Border>
<ContentControl x:Name="MainControl"
IsTabStop="False"
Focusable="False" />
</DockPanel>
</coreClient:BaseWindow>
Hello I want to change color of filter packicon while filtering data from data GridView.
My GridView design like this:-
I want change filter icon color when I pressed apply filter button and remove color when I pressed remove button.
XML code for GridViewColumnHeader:-
<DataGrid HorizontalAlignment="Left" Height="975" VerticalAlignment="Top" Width="1894" AlternationCount="2" AutoGenerateColumns="False"
ItemsSource="{Binding Products}" SelectedItem="{Binding IsSelected}" x:Name="dataGrid" Margin="10,75,-1144,0">
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="Height" Value="50" />
<Setter Property="SeparatorBrush" Value="DarkRed" />
<Setter Property="FontWeight" Value="Black" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
<Grid>
<Border x:Name="columnHeaderBorder"
BorderThickness="1"
Padding="3,0,3,0">
<Border.BorderBrush>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Offset="0" Color="#ecebf2" />
<GradientStop Offset="1" Color="#ecebf2" />
</LinearGradientBrush>
</Border.BorderBrush>
<Border.Background>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Offset="0" Color="#575757" />
<GradientStop Offset="1" Color="#575757" />
</LinearGradientBrush>
</Border.Background>
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Horizontal" Visibility="Visible" Background ="Transparent" >
<TextBlock Text="{Binding}" Style="{StaticResource MaterialDesignCaptionTextBlock}" Foreground="White" Background="Transparent" HorizontalAlignment="Center" Margin="0,5" >
</TextBlock>
<Button x:Name="btnfilter" Command="{ Binding ApplyFilterCommand}" Click="Btnfilter_Click" HorizontalContentAlignment="Right"
HorizontalAlignment="Right" BorderBrush="Transparent" Background="Transparent" Margin="0,-2" >
<materialDesign:PackIcon x:Name="FilterIcon" Kind="Filter" Foreground="White" BorderThickness="0" BorderBrush="Transparent" HorizontalContentAlignment="Right" VerticalAlignment="Center">
<materialDesign:PackIcon.Style>
<Style TargetType="materialDesign:PackIcon" >
<Style.Triggers>
<DataTrigger Binding="{Binding Boolfilteractivate}">
<Setter Property="Foreground" Value="Black">
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</materialDesign:PackIcon.Style>
</materialDesign:PackIcon>
</Button>
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGrid.Resources>
It is common template for all GridViewColumnHeader.
Please suggest how to change filtericon color for particular column.
POPUP code for column header:-
<Popup x:Name="popExcel" Width="300" Height="300" Placement="Bottom" StaysOpen="False">
<Border Background="White" BorderBrush="Gray" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBox x:Name="tbfilter" BorderBrush="Gray" Text="" Foreground="Black" BorderThickness="3" Height="30" Grid.Row="0" Margin="10" TextChanged="Tbfilter_TextChanged" KeyDown="Tbfilter_KeyDown"></TextBox>
<Separator Grid.Row="0" VerticalAlignment="Bottom" Margin="10,0" Height="3"/>
<ListBox x:Name="lbfilter" BorderBrush="Black" BorderThickness="0" Grid.Row="1" Margin="10">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="IsSelected" Value="{Binding IsSelected}"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Style="{StaticResource MaterialDesignAccentCheckBox}" Background="Gray"
IsChecked="{Binding Is_Check, UpdateSourceTrigger=PropertyChanged}" Content="{Binding Title}"></CheckBox>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Button x:Name="ApplyFilter" Style="{StaticResource MaterialDesignRaisedButton}" Foreground="White" Command="{Binding ApplyFilterCommand }" Background="#575757" Click="ApplyFilter_Click" Grid.Row="2" Margin="10">Apply Filter</Button>
<Button x:Name="ClearFilter" Style="{StaticResource MaterialDesignRaisedButton}" Foreground="White" Background="#575757" Click="ClearFilter_Click" Grid.Row="3" Margin="10">Remove Filter</Button>
</Grid>
</Border>
</Popup>
How can we call packicon as child of button
like:-
string colName = "";
Button btn = sender as Button;
ObservableCollection<FilterObj> fltcurrent;
popExcel.PlacementTarget = btn;
StackPanel sp = btn.Parent as StackPanel;
foreach(var ch in sp.Children)
{
if(ch is TextBlock tb)
{
colName = tb.Text;
break;
}
}
foreach (var ch in sp.Children)
{
if (ch is Button bb)
{
}
Because I am unable to call packicon by name:-
Applyfiltermethod
Please help
I find the alternative solution:-
Here is the code:-
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Horizontal" Visibility="Visible" Background ="Transparent" >
<TextBlock Text="{Binding}" Style="{StaticResource MaterialDesignCaptionTextBlock}" Foreground="White" Background="Transparent" HorizontalAlignment="Center" Margin="0,5" >
</TextBlock>
<Button x:Name="btnfilter" Click="Btnfilter_Click" HorizontalContentAlignment="Right"
HorizontalAlignment="Right" BorderBrush="Transparent" Background="Transparent" Margin="0,-2" >
<materialDesign:PackIcon x:Name="FilterIcon" Kind="Filter" Foreground="White" BorderThickness="0" BorderBrush="Transparent" HorizontalContentAlignment="Right" VerticalAlignment="Center">
</materialDesign:PackIcon>
</Button>
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
Some code need to add in CS file as well.
PackIcon wantedchild;
IList<PackIcon> wantedchilds = new List<PackIcon>();
Button button = sender as Button;
object wantedNode = button.FindName("FilterIcon");
if (wantedNode is PackIcon)
{
wantedchild = wantedNode as PackIcon;
wantedchilds.Add(wantedchild);
}
Add button code:-`
foreach(var child in wantedchilds)
{
child.Foreground = Brushes.Blue;
} `
Remove button code:-
foreach (var child in wantedchilds)
{
child.Foreground = Brushes.White;
}
wantedchilds.Clear();
I have some ListViews who each can contain max 5 ListViewItems. As long as there are less than 5 items there should be an Button be displayed. I have already written an Value Converter that returns true if the Count is less than five. But now I have Problems styling my ListView. Because i.e. if there are three ListViewItems they should be styled with the normal style and the "4" item should be an Button. My tought was that I add a new ListViewItem inside the DataTrigger. Is that possible or is there a better way to achive that?
Style.xaml
<Style TargetType="{x:Type ListView}">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<UniformGrid Rows="5" Columns="1"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Disabled"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=Items.Count, Converter={StaticResource ItemCounterConverter}}" Value="true">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<TextBlock>No items to display</TextBlock>
</ControlTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
<!--ListViewItem-->
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListViewItem}">
<Border BorderBrush="#5076A7" BorderThickness="1">
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="#FFFFFF" Offset="0.0"/>
<GradientStop Color="#C0D3EA" Offset="1.0"/>
</LinearGradientBrush>
</Border.Background>
<StackPanel TextElement.FontFamily="Segoe UI" TextElement.FontSize="12">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="15"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Padding="3,0,0,0" Text="{Binding Betreff}" TextTrimming="CharacterEllipsis" Grid.Column="0" Grid.Row="0"/>
<Button FontSize="7" Content="X" Grid.Column="1" Grid.Row="0"/>
</Grid>
<TextBlock Padding="3,0,0,0" Text="{Binding Kunde}"/>
<StackPanel Orientation="Horizontal">
<TextBlock FontWeight="Bold" Padding="3,0,0,0" Text="{Binding Ort}"/>
<TextBlock Padding="3,0,0,0" Text="("/>
<TextBlock Text="{Binding Alternative}"/>
<TextBlock Text=")"/>
</StackPanel>
</StackPanel>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Update
Thanks this looks very promising and you understood it right. But I have problems implementing it. Every ListView has a differnt ItemSource(they're all ObservableCollections), so I don't know if I can set the ItemSource inside the Style? But the Button at the End should be available to all of them. My Styles are in a different File than the ListViews themselves. The definition for my ListViews looks like this:
AppointmentOverview.xaml
<ListView Grid.Column="1" Grid.Row="3" ItemsSource="{Binding Mov}"/>
<ListView Grid.Column="1" Grid.Row="4" ItemsSource="{Binding Mon}"/>
<ListView Grid.Column="2" Grid.Row="3" ItemsSource="{Binding Div}"/>
<ListView Grid.Column="2" Grid.Row="4" ItemsSource="{Binding Div}"/>
<ListView Grid.Column="3" Grid.Row="3" ItemsSource="{Binding Miv}"/>
<ListView Grid.Column="3" Grid.Row="4" ItemsSource="{Binding Min}"/>
<ListView Grid.Column="4" Grid.Row="3" ItemsSource="{Binding Dov}"/>
<ListView Grid.Column="4" Grid.Row="4" ItemsSource="{Binding Don}"/>
<ListView Grid.Column="5" Grid.Row="3" ItemsSource="{Binding Frv}"/>
<ListView Grid.Column="5" Grid.Row="4" ItemsSource="{Binding Frn}"/>
I need to set change background color for list item when mouse is over. Here is my code:
<DataTemplate x:Key="ListBoxSubCategoryListTemplate" DataType="{x:Type ListBoxItem}">
<StackPanel>
<Button x:Name="btnSubCategoryList" Template="{StaticResource subCategoryListItems}"
Content="{Binding Path=sub_category_name}"
Background="Transparent"
Height="25"/>
</StackPanel>
</DataTemplate>
<ControlTemplate x:Key="subCategoryListItems" TargetType="{x:Type Button}">
<StackPanel FlowDirection="LeftToRight" Orientation="Horizontal" >
<TextBlock Width="150"
Height="{TemplateBinding Button.Height}"
x:Name="textBlockSubCategoryName"
Background="{TemplateBinding Button.Background}"
Text="{TemplateBinding Button.Content}"
FontWeight="Bold" />
<Image x:Name="img" Width="15" Height="15" Source="/ExpressFurnitureSystem;component/Images/edit.png" ToolTip="Click to edit"></Image>
</StackPanel>
</ControlTemplate>
Please help...How??
How about a Trigger such as:
<DataTemplate x:Key="ListBoxSubCategoryListTemplate" DataType="{x:Type ListBoxItem}">
<StackPanel>
<Button x:Name="btnSubCategoryList" Template="{StaticResource subCategoryListItems}"
Content="{Binding Path=sub_category_name}"
Background="Transparent"
Height="25"/>
</StackPanel>
<DataTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="btnSubCategoryList" Property="Background" Value="Blue" />
</Trigger>
</DataTemplate.Triggers>
</DataTemplate>