I have an expander containing a list view. The expander is initially disabled, and enabled sometime after the application is started.
Everything works great if before InitializeComponent() I populate the ListView's ItemsSource (some observable collection, created of course before InitializeComponent) with at least one item. The expander expands correctly, items show as they should. The only problem then is that new items that require more space to be rendered appear cropped - I assume this means the ListView isn't refreshing properly?
However, if I add items to the collection anytime after InitializeComponent(), the expander only expands a little bit (just a few pixels). When I force the ListView's Width to be some large value, the expander does expand, but items inserted into the list are rendered just with the background color, with no content...
I assume this has something to do with the ListView initialization, refresh or what have you. Code follows:
XAML:
<DockPanel Name="mainPanel">
<Expander DockPanel.Dock="Right" ExpandDirection="Right" IsExpanded="False" IsEnabled="{Binding ExpanderEnabled}">
<Expander.Style>
<Style TargetType="Expander">
<Setter Property="Background" Value="#FFFF3333" />
<Style.Triggers>
<DataTrigger Binding="{Binding ExpanderEnabled}" Value="True">
<Setter Property="Background" Value="LightGreen" />
</DataTrigger>
</Style.Triggers>
</Style>
</Expander.Style>
<Expander.Header>
<Grid Width="30" VerticalAlignment="Top" HorizontalAlignment="Left">
<Grid Width="300" Height="300" VerticalAlignment="Top" HorizontalAlignment="Left">
<TextBlock Text="Expander Name" FontSize="12" FontWeight="Bold" Margin="22,170,0,0" VerticalAlignment="Center" HorizontalAlignment="Left" RenderTransformOrigin="0,1">
<TextBlock.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="-90"/>
<TranslateTransform/>
</TransformGroup>
</TextBlock.RenderTransform>
</TextBlock>
</Grid>
</Grid>
</Expander.Header>
<ListView ItemsSource="{Binding Items}" BorderBrush="LightGreen" BorderThickness="3">
<ListView.Style>
<Style TargetType="ListView">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Black"/>
</Style.Resources>
</Style>
</ListView.Style>
<ListView.View>
<GridView>
<GridView.ColumnHeaderContainerStyle>
<Style TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="Visibility" Value="Collapsed"/>
</Style>
</GridView.ColumnHeaderContainerStyle>
<GridViewColumn DisplayMemberBinding="{Binding Path=A, Converter={StaticResource aConverter}}" Width="Auto" />
<GridViewColumn DisplayMemberBinding="{Binding Path=B, Converter={StaticResource bConverter}}" Width="Auto" />
<GridViewColumn DisplayMemberBinding="{Binding Path=C, Converter={StaticResource cConverter}}" Width="Auto" />
<GridViewColumn DisplayMemberBinding="{Binding Path=D, StringFormat='\{0\} ds'}" Width="Auto" />
</GridView>
</ListView.View>
</ListView>
</Expander>
...
Related
I have a ListView with GridView content as below. I just add the delete and edit button to the end of each row. So i don't need the header for those columns. I collopsed the headers for those columns, this removes the headers but the place of the header of the columns looks like white as below. How to set the style for those columns as the header bar style ?
<Style x:Key="sahin" TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="Visibility" Value="Collapsed"></Setter>
</Style>
<ListView Grid.Row="3" ItemsSource="{Binding deckList}" >
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Center"></Setter>
<Setter Property="VerticalContentAlignment" Value="Center"></Setter>
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn Header="Name" Width="120" DisplayMemberBinding="{Binding Name}" />
<GridViewColumn Header="Surname" Width="120" DisplayMemberBinding="{Binding SurName}" />
<GridViewColumn HeaderContainerStyle="{StaticResource sahin}" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button Style="{StaticResource noBackgroundStyle}">
<Image Source="/KillCard;component/Resources/Images/delete.png" Width="16"></Image>
</Button>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn HeaderContainerStyle="{StaticResource sahin}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button Style="{StaticResource noBackgroundStyle}">
<Image Source="/KillCard;component/Resources/Images/edit.png" Width="16"></Image>
</Button>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
The code snippet shown below helped me.
<Style x:Key="sahin" TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
<Border x:Name="HeaderBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0,1,0,1" Background="{TemplateBinding Background}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I'm trying to add a tooltip to children in a TreeView in WPF. However, it appears even in the XAML I can't get a tooltip to render in the treeview children. Can someone please tell me how to get around this?
<Window x:Class="Client_Invoice_Auditor.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Client_Invoice_Auditor"
xmlns:self="clr-namespace:Client_Invoice_Auditor.CoreClientAR"
mc:Ignorable="d"
Title="Client Invoice Auditor" Height="450" Width="1000">
<Window.Resources>
<self:SPConverter x:Key="SPConverter"/>
<self:ErrorExpandConverter x:Key="ErrorExpandConverter"/>
<self:AssignRowConverter x:Key="AssignRowConverter"/>
<self:IssueIconConverter x:Key="IssueIconConverter"/>
</Window.Resources>
<Grid>
<Grid.ColumnDeitions>
</Grid.ColumnDeitions>
<Grid.RowDeitions>
<RowDeition Height="20*"/>
<RowDeition Height="80*"/>
</Grid.RowDeitions>
<Grid Grid.Row="0" Grid.Column="0">
<StackPanel Orientation="Vertical">
<DockPanel VerticalAlignment="Top" Height="20" Panel.ZIndex="1">
<Menu Name="fileMenu" Width="Auto" DockPanel.Dock="Top">
<MenuItem Header="File">
<MenuItem Header="Open Account File" Click="menuOpenFile_Click"/>
<MenuItem Header="Exit" Click="menuExit_Click"/>
</MenuItem>
<MenuItem Header="Options">
<!--<MenuItem Header="Update" Click="update_Click"/>-->
<MenuItem Header="About" Click="about_Click"/>
</MenuItem>
</Menu>
</DockPanel>
<WrapPanel Orientation="Horizontal" HorizontalAlignment="Center" Height="Auto">
<StackPanel Width="Auto" Orientation="Horizontal" HorizontalAlignment="Center">
<Border BorderBrush="MediumAquamarine" BorderThickness="2">
<Label Name="AccountNumber"/>
</Border>
<Border BorderBrush="MediumAquamarine" BorderThickness="2">
<Label Name="AcctDesc"/>
</Border>
<Border BorderBrush="MediumAquamarine" BorderThickness="2">
<Label Name="Organization"/>
</Border>
</StackPanel>
</WrapPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<Label Margin="20,10,0,0" Content="Activity Date Time" />
<Label Margin="60,10,0,0" Content="Beginning Balance" />
<Label Margin="10,10,0,0" Content="Charge Amount" />
<Label Margin="30,10,0,0" Content="Adjustments" />
<Label Margin="40,10,0,0" Content="Payments" />
<Label Margin="60,10,0,0" Content="End Balance" />
<Label Margin="50,10,0,0" Content="Issues" />
</StackPanel>
</StackPanel>
</Grid>
<Grid Grid.Row="1" Grid.Column="0">
<Grid Name="IssuesGrid">
<Grid.ColumnDeitions>
<!--<ColumnDeition Width="80*"/>-->
<!--<ColumnDeition Width="20*"/>-->
</Grid.ColumnDeitions>
<TreeView Name="View">
<!--<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded"
Value="{Binding Class, Converter={StaticResource ErrorExpandConverter}}" />
</Style>-->
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded"
Value="{Binding Dummies, Converter={StaticResource ErrorExpandConverter}}" />
</Style>
</TreeView.ItemContainerStyle>
<TreeView.ItemTemplate>
<HierarchicalDataTemplate DataType="{x:Type self:dailyAccountBalance}" ItemsSource="{Binding Dummies}">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" IsEnabled="False" Grid.Row="{Binding RowIndex}" ToolTip="This info">
<TextBlock Width="150" Text="{Binding ActivityDate}" />
<TextBlock Width="100" Margin="20,0,0,0" Text="{Binding BegBalance}"/>
<TextBlock Width="100" Margin="20,0,0,0" Text="{Binding ChrgAmount}" />
<TextBlock Width="100" Margin="20,0,0,0" Text="{Binding AdjAmount}" />
<TextBlock Width="100" Margin="20,0,0,0" Text="{Binding PmtAmount}" />
<TextBlock Width="100" Margin="20,0,0,0" Text="{Binding EndBalance}" ToolTipService.IsEnabled="True" ToolTipService.ToolTip="This balance thing" ToolTip="This balance"/>
<ContentControl HorizontalAlignment="Left" Margin="20,0,0,0" Width="100" ToolTip="This">
<ContentControl.Content>
<MultiBinding Converter="{StaticResource IssueIconConverter}">
<Binding Path="RowIndex"/>
<Binding Path="Errors"/>
</MultiBinding>
</ContentControl.Content>
<!--<TextBlock Text="Test"/>-->
</ContentControl>
</StackPanel>
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate DataType="{x:Type self:DummyItem}">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<!--<TextBlock Text="{Binding Text}" />-->
<DataGrid ItemsSource="{Binding ChargeActivities}" AutoGenerateColumns="False">
<DataGrid.Style>
<Style TargetType="{x:Type DataGrid}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Items.Count,
RelativeSource={RelativeSource Self}}" Value="0">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.Style>
<DataGrid.Columns>
<DataGridTextColumn x:Name="ChrgID" Header=" Charge" Binding="{Binding ChargeID}" />
<DataGridTextColumn x:Name="ChrgType" Header="Charge Type" Binding="{Binding ChargeType}">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Style.Triggers>
<Trigger Property="Text" Value="CR">
<Setter Property="Foreground" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn x:Name="ChrgAmt" Header="Amount" Binding="{Binding ChargeAmount}">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Style.Triggers>
<DataTrigger Binding="{Binding ChargeType}" Value="CR">
<Setter Property="Foreground" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn x:Name="" Header="" Binding="{Binding Stuff}" />
<DataGridTextColumn x:Name="Class" Header=" Class" Binding="{Binding Class}">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="{Binding Class, Converter={StaticResource SPConverter}}"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</StackPanel>
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
<!--<TreeViewItem x:Key="Test">
<TextBlock Text="Me gusta"></TextBlock>
</TreeViewItem>-->
</TreeView.ItemTemplate>
</TreeView>
</Grid>
</Grid>
</Grid>
</Window>
Any suggestions to get tooltips to render in the treeview children would definitely be appreciated. Thanks a ton in advance.
You don't set the tooltip property of elements inside of the template, you set it on the TreeViewItem itself.
Here is a very simplified example:
<TreeView>
<TreeViewItem Header="Item #1" DataContext="Test1" />
<TreeViewItem Header="Item #2" DataContext="Test2" />
<TreeView.Resources>
<Style TargetType="{x:Type TreeViewItem}">
<Style.Setters>
<Setter Property="ToolTip" Value="{Binding}" />
</Style.Setters>
</Style>
</TreeView.Resources>
</TreeView>
Here I had to set the DataContext manually and hardcoded for the example to work since just using the Header property doesn't set it, but in the real world, you are going to be data bound, so it will be set.
I have a listview that uses GroupStyles where the ColumnHeaders are shown in each group. This works fine.
I would however like to hide the original ListView ColumnHeader (seen at the top of image) and just show Headers within the groups.
How can I separate them so it only show in the groups?
The GroupStyle:
<Style x:Key="GroupingSerialStyle" TargetType="{x:Type GroupItem}" BasedOn="{StaticResource GroupingBase}">
<Setter Property = "Template">
<Setter.Value>
<ControlTemplate>
<Expander Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" IsExpanded="{Binding IsExpandedAll, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Mode=OneTime}" Margin="2">
<Expander.Header>
<StackPanel Orientation = "Horizontal">
<TextBlock Text=" # "/>
<TextBlock Text = "{Binding Name}" />
</StackPanel>
</Expander.Header>
<StackPanel Orientation="Vertical">
<GridViewHeaderRowPresenter Visibility = "Visible" Margin="15,0,0,0"
DataContext="{Binding View, RelativeSource={RelativeSource FindAncestor,ListView,1}}"
Columns="{Binding Columns}"
ColumnHeaderContainerStyle="{StaticResource GridViewColumnHeaderStyleABCD}"
ColumnHeaderTemplate="{Binding ColumnHeaderTemplate}"
ColumnHeaderTemplateSelector="{Binding ColumnHeaderTemplateSelector}"
AllowsColumnReorder="{Binding AllowsColumnReorder}"
ColumnHeaderContextMenu="{Binding ColumnHeaderContextMenu}"
ColumnHeaderToolTip="{Binding ColumnHeaderToolTip}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
<ItemsPresenter Margin = "15,0,0,0" />
</StackPanel>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Edit: Further the column headers shall presented with custom colors for each column.
It can be solved through the ColumnHeaderContainerStyle. If you set an empty Template at GridView.ColumnHeaderContainerStyle and use your styled GridViewColumnHeaderStyleABCD for your GroupItem it should work.
I tried the following, that only displays column headers at the group items with customized Background.
<ListView BindingGroup="{Binding Name}" ItemsSource="{Binding Source={StaticResource TestItems}}">
<!-- ### custom coloring column headers ### -->
<ListView.Resources>
<Style TargetType="GridViewColumnHeader">
<Setter Property="Background" Value="{Binding Path=Column.(YourNamespace:BgHelper.CustomBackground), RelativeSource={RelativeSource Self}}" />
</Style>
</ListView.Resources>
<ListView.View>
<GridView>
<GridView.ColumnHeaderContainerStyle>
<Style TargetType="GridViewColumnHeader">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
<!-- Empty: ListViews header shows nothing -->
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GridView.ColumnHeaderContainerStyle>
<!-- ### custom coloring column headers ### -->
<GridViewColumn DisplayMemberBinding="{Binding Parameter0}" Header="Par0" YourNamespace:BgHelper.CustomBackground="Pink" />
<GridViewColumn DisplayMemberBinding="{Binding Parameter1}" Header="Par1" YourNamespace:BgHelper.CustomBackground="Green" />
</GridView>
</ListView.View>
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<Expander Margin="2">
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text=" # " />
<TextBlock Text="{Binding Name}" />
</StackPanel>
</Expander.Header>
<StackPanel Orientation="Vertical">
<GridViewHeaderRowPresenter Margin="15,0,0,0"
Columns="{Binding Columns}"
DataContext="{Binding View, RelativeSource={RelativeSource FindAncestor, ListView, 1}}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
Visibility="Visible" />
<ItemsPresenter Margin="15,0,0,0" />
</StackPanel>
</Expander>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListView.GroupStyle>
</ListView>
To customize your column header colors you could use an AttachedProperty as follows:
namespace YourNamespace
{
public class BgHelper
{
#region Fields
public static DependencyProperty CustomBackgroundProperty =
DependencyProperty.RegisterAttached("CustomBackground",
typeof (SolidColorBrush),
typeof (BgHelper),
new FrameworkPropertyMetadata(new SolidColorBrush(Colors.Transparent)));
#endregion
#region Public Methods
public static SolidColorBrush GetCustomBackground(DependencyObject element)
{
return (SolidColorBrush) element.GetValue(CustomBackgroundProperty);
}
public static void SetCustomBackground(DependencyObject element, SolidColorBrush value)
{
element.SetValue(CustomBackgroundProperty, value);
}
#endregion
}
}
Then I extended my example above with setting the CustomBackground and using it at GridViewColumnHeader style. I marked the new/edited lines with comments.
#WPFGermany was correct. However, in my original question I forgot to add that for the headers within the GroupStyle I also needed to show different background colors for some of the column headings. I was able to get this to work by duplicating all of the columns in the GroupStyle and pointing each ColumnHeaderStyle to a unique color. Perhaps there is a better way but for now this works for me. Here is the partial GroupStyle to illustrate:
<Style x:Key="GroupingNcpCheckStyleRoot" TargetType="{x:Type GroupItem}" BasedOn="{StaticResource GroupingBaseRoot}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Expander Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" IsExpanded="{Binding IsExpandedData, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Mode=OneTime}" Margin="2">
<Expander.Header>
<StackPanel Orientation="Horizontal">
<CheckBox x:Name="HeaderCheckBox" Margin="0,0,6,0" IsChecked="True"></CheckBox>
<TextBlock Text=" # "/>
<TextBlock Text="{Binding Name}"/>
</StackPanel>
</Expander.Header>
<StackPanel Orientation="Vertical">
<GridViewHeaderRowPresenter Margin="15,0,0,0"
DataContext="{Binding View, RelativeSource={RelativeSource FindAncestor, ListView, 1}}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
Visibility="Visible" >
<GridViewHeaderRowPresenter.Columns>
<!--NOTE: must explicitly create the collection-->
<GridViewColumnCollection>
<GridViewColumn Header=" " Width="60" >
<GridViewColumn.HeaderContainerStyle>
<Style TargetType="{x:Type GridViewColumnHeader}" BasedOn="{StaticResource GridViewColumnHeaderStyleTEST1}">
<Setter Property="Background" Value="{StaticResource TargetHeaderColor}" />
<Setter Property="Foreground" Value="White" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Margin" Value="-1,0,-1,0" />
</Style>
</GridViewColumn.HeaderContainerStyle>
<GridViewColumn.CellTemplate>
<DataTemplate >
<TextBlock HorizontalAlignment="Left" Text="{Binding Path=Id, StringFormat='# {0}'}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header=" Show " >
<GridViewColumn.HeaderContainerStyle>
<Style TargetType="{x:Type GridViewColumnHeader}" BasedOn="{StaticResource GridViewColumnHeaderStyleTEST1}">
<Setter Property="Background" Value="{StaticResource DifferentHeaderColor}" />
<Setter Property="Foreground" Value="White" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Margin" Value="-1,0,-1,0" />
</Style>
</GridViewColumn.HeaderContainerStyle>
<GridViewColumn.CellTemplate>
<DataTemplate >
<CheckBox IsChecked="{Binding Path=IncludeInReport}" HorizontalAlignment="center"></CheckBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
Hi please keep in mind I am new with WPF, I am using a WebService that returns a gridlist[] and it automatically populate my Gridview. here is the WebService:
C#:
WebService.Contacts Contact = new WebService.Contacts();
grdGetGroup.ItemsSource = Contact.GetGroups(Username, Password);
Here is my XAML:
<ListView x:Name="grdGetGroup"
Margin="560,34,128,48"
FontSize="13"
BorderBrush="#FFF01F1F"
Foreground="#FFF01F1F"
SelectedIndex="1"
FontFamily="/WPF Working Experimenet;component/Font/#B Nazanin">
<ListView.View>
<GridView>
<GridViewColumn x:Name="GridID"
Header="ID"
Width="50"
DisplayMemberBinding="{Binding GroupID}"
FrameworkElement.FlowDirection="RightToLeft" />
<GridViewColumn Header="Group Name"
Width="85
"
DisplayMemberBinding="{Binding GroupName}"
FrameworkElement.FlowDirection="RightToLeft" />
<GridViewColumn Header="Numbers"
Width="60"
DisplayMemberBinding="{Binding ContactCount}"
FrameworkElement.FlowDirection="RightToLeft" />
<GridViewColumn Header="Access"
Width="60"
DisplayMemberBinding="{Binding ShowToChild}"
FrameworkElement.FlowDirection="RightToLeft" />
<GridViewColumn Header="Description"
Width="150"
DisplayMemberBinding="{Binding GroupDescription}"
FrameworkElement.FlowDirection="RightToLeft" />
<GridViewColumn Header=""
Width="60"
FrameworkElement.FlowDirection="RightToLeft">
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<Button x:Name="btnChangeGroup"
Margin="5"
Content="Change"
Cursor="Hand"
Click="btnChangeGroup_Click">
<Button.Template>
<ControlTemplate TargetType="Button">
<TextBlock TextDecorations="Underline">
<ContentPresenter /></TextBlock>
</ControlTemplate>
</Button.Template>
<Button.Style>
<Style TargetType="Button">
<Setter Property="Foreground"
Value="Black" />
<Style.Triggers>
<Trigger Property="IsMouseOver"
Value="true">
<Setter Property="Foreground"
Value="Red" />
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header=""
Width="60"
FrameworkElement.FlowDirection="RightToLeft">
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<Button x:Name="btnRemoveGroup"
Margin="5"
Content="Remove"
Cursor="Hand"
Click="btnRemoveGroup_Click">
<Button.Template>
<ControlTemplate TargetType="Button">
<TextBlock TextDecorations="Underline">
<ContentPresenter /></TextBlock>
</ControlTemplate>
</Button.Template>
<Button.Style>
<Style TargetType="Button">
<Setter Property="Foreground"
Value="Black" />
<Style.Triggers>
<Trigger Property="IsMouseOver"
Value="true">
<Setter Property="Foreground"
Value="#FFF01F1F" />
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
If you have noticed, I have 2 button for every row in Gridview which is built automatically as well, now here is my question how to extract the Data in GridviewColumn x:Name"GridID"? and pass it to the same row's Button Click Event (Which has a method that takes the Data has an input)
Valkyry,
If I undestand/guess right, on every line you ve got a gridList item.
If I undestand/guess right each gridList has a GroupID property.
Correct me if am wrong.
In WPF, in a DataGrid, each line has a DataContext property that holds the data of the line :
void btnRemoveGroup_Click( Object sender, EventArgs args)
{
var fxElt = sender as FrameworkElement;
var lineData = fxElt.DataContext as gridlist;
int groupID = lineData .GroupID;
}
Tell me it works or not. Regards
I have a problem with setting datagrid event.
I want to register the datagrid inside the ListView with the following event :
CellEditEnding="dataGridInstallationProperties_CellEditEnding"
However, since i set the DataContext of this datagrid on the fly, the application throws NulleferenceException
Is there a way to get this collection of datagrids inside the list view and set this event programatically in C# for each one of them?
Below is my xaml :
<ListView x:Name="listViewInstallProperties"
Height="Auto"
Width="Auto"
ItemsSource="{Binding InstallPackage.Features.FeaturesList}"
BorderBrush="{x:Null}" Foreground="{x:Null}"
Background="{x:Null}">
<ListView.Resources>
<DataTemplate x:Key="ExpanderInstallPropsItemTemplate">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<Expander x:Name="expanderInstallationProperties" Header="{Binding DisplayName}"
Visibility="{Binding Path=IsSelected, Converter={StaticResource boolToVis}, Mode=TwoWay}"
Grid.Column="0" HorizontalAlignment="Left"
Margin="0,0,0,-0.001"
d:LayoutOverrides="Height, GridBox" Width="600">
<DataGrid x:Name="dataGridInstallationProperties"
CellEditEnding="dataGridInstallationProperties_CellEditEnding"
CanUserAddRows="False" AutoGenerateColumns="False"
ItemsSource="{Binding Path=Properties}"
Margin="0" RenderTransformOrigin="-1.6,-1.231" Background="White"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch" VerticalContentAlignment="Top"
d:LayoutOverrides="GridBox" BorderBrush="{x:Null}" RowBackground="{x:Null}">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Description}"
Header="Property" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding Value, UpdateSourceTrigger=PropertyChanged}"
Header="Value" />
<DataGridTemplateColumn Header="Restore"
CellTemplate="{StaticResource RestoreDefaultPropertyButtonTemplate}" />
</DataGrid.Columns>
</DataGrid>
</Expander>
</ScrollViewer>
</DataTemplate>
</ListView.Resources>
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Style.Triggers>
<Trigger Property="IsSelected"
Value="True">
<Setter Property="Background"
Value="{x:Null}" />
<Setter Property="BorderBrush"
Value="{x:Null}" />
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn Header="Extend The Feature To Get Its Related Properties" CellTemplate="{StaticResource ExpanderInstallPropsItemTemplate}" />
</GridView>
</ListView.View>
Thanks !