I’ve a XAML Code with a Listview. Now I want to change the CellTemplate with a button
but without code behind. How can I do this?
Templates:
<DataTemplate x:Key="URL" >
<TextBlock>
<Hyperlink NavigateUri="{Binding XPath=@URL}">
<TextBlock Text="{Binding XPath=@URL}"/>
</Hyperlink>
</TextBlock>
</DataTemplate>
<DataTemplate x:Key="Text">
<TextBlock Text="{Binding XPath=@URL}"/>
</DataTemplate>
<Grid>
<Grid.Resources>
<XmlDataProvider x:Key="Data">
<x:XData>
<Data xmlns="">
<Item ID="1" Desc="Google" URL="http://www.google.com" Acceptable="true"/>
<Item ID="2" Desc="StackOverflow" URL="http://www.stackoverflow.com" Acceptable="true"/>
<Item ID="3" Desc="4chan" URL="http://www.4chan.org" Acceptable="false"/>
</Data>
</x:XData>
</XmlDataProvider>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="300"/>
</Grid.ColumnDefinitions>
Here is the button where magic should happen and set the CellTemplate from URLColumn.
I want to have Text as CellTemplate when I click on this button.
<Button Grid.Column="0"
Name="Text"
Content="Text"/>
Listview with the GridViewColumn URLColumn. I want to change it’s CellTemplate.
<ListView
Grid.Column="1"
DataContext="{Binding Source={StaticResource Data}, XPath=/Data}"
ItemsSource="{Binding XPath=Item}">
<ListView.View>
<GridView>
<GridViewColumn Header="ID" DisplayMemberBinding="{Binding XPath=@ID}"/>
<GridViewColumn Header="Description" DisplayMemberBinding="{Binding XPath=@Desc}"/>
<GridViewColumn x:Key="URLColumn" Header="URL" CellTemplate="{StaticResource URL}"/>
<GridViewColumn Header="Acceptable">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding XPath=@Acceptable}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
Is this without code behind possible? If so, how?
I’ve already search the internet the whole day, but couldn’t find an anwser.
Thanks for any help!
First install Expression Blend Interactivity NuGet package (or add reference to
Microsoft.Expression.Interactions.dllfrom Expression Blend SDK manually):Then use
ChangePropertyActiontrigger action: