I have an application with 2 tabs which are Person and User Management in WPF with MVVM. Now the problem is when I click on Person Mag tab, the PersonViewModel will bind to Person Mag View, and User Mag same as mentioned situation also.
How to make Person and User Mag tab bind its view model at start of the application (both bind viewmodel for its own view at the same time) instead of bind the view model when I clicked on that tab.
XAML
<DockPanel LastChildFill="True">
<TabControl TabStripPlacement="Left" DockPanel.Dock="Left" Margin="5">
<TabItem Width="190" Margin="1">
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<Image Source="/Images/Person-Management-Icon.png" Width="32" Height="32" />
<TextBlock Text="Person Mangement" Margin="5,0,0,0" VerticalAlignment="Center" />
</StackPanel>
</TabItem.Header>
<TabItem.ContentTemplate>
<DataTemplate>
<ptab:PersonManagementView />
</DataTemplate>
</TabItem.ContentTemplate>
</TabItem>
<TabItem Margin="1">
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<Image Source="/Images/User-Management-Icon.png" Width="32" Height="32" />
<TextBlock Text="User Mangement" Margin="5,0,0,0" VerticalAlignment="Center" />
</StackPanel>
</TabItem.Header>
<TabItem.ContentTemplate>
<DataTemplate>
<ptab:UserManagementView />
</DataTemplate>
</TabItem.ContentTemplate>
</TabItem>
</TabControl>
</DockPanel>
PersonManagement XAML
<!--View Model Section-->
<UserControl.DataContext>
<vm:PersonViewModel />
</UserControl.DataContext>
<!--End View Model Section-->
<!--Resources Section-->
<UserControl.Resources>
<ResourceDictionary Source="../Resources/ResourceDictionary.xaml" />
</UserControl.Resources>
<!--End Resources Section-->
<DockPanel Name="Person_Management_View">
<TabControl DockPanel.Dock="Top">
<TabItem>
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<Image Source="/Images/Person-Creation-Icon.png" Width="24" Height="24" />
<TextBlock Text="Person Creation" Margin="5,0,0,0" VerticalAlignment="Center" />
</StackPanel>
</TabItem.Header>
<Grid>
<Grid.RowDefinitions>
<!--Name-->
<RowDefinition Height="Auto" />
<!--Gender-->
<RowDefinition Height="Auto" />
<!--Department-->
<RowDefinition Height="Auto" />
<!--Error Message-->
<RowDefinition Height="25" />
<!--Save Button-->
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="50" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<!--Name Section-->
<Label Grid.Row="0" Grid.Column="0" Content="Name"/>
<Label Grid.Row="0" Grid.Column="1" Content=":"/>
<TextBox Name="txtPersonName" Grid.Row="0" Grid.Column="2" Margin="4">
<TextBox.Text>
<Binding Path="PersonObject.Name" UpdateSourceTrigger="PropertyChanged" >
<Binding.ValidationRules>
<r:PersonNameRule ValidatesOnTargetUpdated="True" />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
<!--End Name Section-->
<!--Gender Section-->
<Label Grid.Row="1" Grid.Column="0" Content="Gender"/>
<Label Grid.Row="1" Grid.Column="1" Content=":"/>
<ComboBox Grid.Row="1" Grid.Column="2" Margin="4" ItemsSource="{Binding GenderList}" SelectedItem="{Binding PersonObject.Gender}"/>
<!--End Gender Section-->
<!--Department Section-->
<Label Grid.Row="2" Grid.Column="0" Content="Department" />
<Label Grid.Row="2" Grid.Column="1" Content=":"/>
<ComboBox Grid.Row="2" Grid.Column="2" Margin="4" ItemsSource="{Binding DepartmentList}" SelectedItem="{Binding PersonObject.DepartmentName}" />
<!--End Department Section-->
<!--Error Message Section-->
<TextBlock Grid.Row="3" Grid.Column="2" Margin="4,4,4,0" Visibility="{Binding ElementName=txtPersonName, Path=(Validation.Errors), Converter={StaticResource toVisibilityConverter}}" Style="{StaticResource RedTextBlock}">
<TextBlock.Text>
<Binding ElementName="txtPersonName" Path="(Validation.Errors).CurrentItem.ErrorContent"/>
</TextBlock.Text>
</TextBlock>
<!--End Error Message Section-->
<!--Save Button Section-->
<Button Grid.Row="4" Grid.Column="2" HorizontalAlignment="Right" MinWidth="100" Margin="4,0,4,4" Content="Save" Command="{Binding CreatePersonCommand}">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="IsEnabled" Value="false" />
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding ElementName=txtPersonName, Path=(Validation.HasError)}" Value="false" />
</MultiDataTrigger.Conditions>
<Setter Property="IsEnabled" Value="true" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
<!--End Save Button Section-->
</Grid>
</TabItem>
</TabControl>
<!--Person Data Section-->
<DataGrid Name="PersonDataGrid" DockPanel.Dock="Bottom" AutoGenerateColumns="False" IsReadOnly="True" SelectionMode="Single" ColumnWidth="*" ItemsSource="{Binding PersonList}">
<DataGrid.Columns>
<DataGridTextColumn Header="Id" Binding="{Binding PersonID}" />
<DataGridTextColumn Header="Name" Binding="{Binding Name}" />
<DataGridTextColumn Header="Gender" Binding="{Binding Gender, Converter={StaticResource emptyStringConverter}}" />
<DataGridTextColumn Header="Department" Binding="{Binding DepartmentName, Converter={StaticResource emptyStringConverter}}" />
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button IsEnabled="{Binding Selected, Converter={StaticResource oppositeBoolConverter}}" Command="{Binding DataContext.DeletePersonCommand, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" CommandParameter="{Binding PersonID}" Style="{StaticResource TransparentButton}">
<Image Source="{Binding Selected, Converter={StaticResource deleteImageConverter}}" Width="16" Height="16"/>
</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Command="{Binding DataContext.ViewPersonCommand, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" CommandParameter="{Binding PersonID}" Style="{StaticResource TransparentButton}">
<Image Source="/Images/Update-Icon.png" Width="16" Height="16"/>
</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
<!--End Person Data Section-->
</DockPanel>
Try this
Add Loaded event to TabControl
<TabControl TabStripPlacement="Left" DockPanel.Dock="Left" Margin="5" Loaded="Tab_OnLoaded" >
Remove the ContentTemplate from xaml and assign content in code like
void Tab_OnLoaded(object sender, RoutedEventArgs e)
{
var tabControl = sender as TabControl;
if (tabControl != null)
{
for (int i = 0; i < tabControl.Items.Count; i++)
{
if (i == 1)
(tabControl.Items[i] as TabItem).Content = new UserControl2();//Here assign the Usercontrol that you want to set as Content
}
tabControl.Loaded -= Tab_OnLoaded; // Do this on first time only
}
}
I dont think its a good approach . I hope this will help.
Related
I have a ListBox :
<ListBox Margin="10" Padding="10" ItemsSource="{Binding Items}">
<ListBox.ItemTemplate>
<DataTemplate>
<!-- Data template -->
<Grid>
<Grid.ColumnDefinitions>
<!--Image-->
<ColumnDefinition Width="auto" />
<!--Info-->
<ColumnDefinition Width="500" />
<!--Options-->
<ColumnDefinition Width="*" /
</Grid.ColumnDefinitions>
<Image Height="50" Width="50" />
<StackPanel Grid.Column="1" HorizontalAlignment="Left">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Name: " />
<TextBlock Text="{Binding Name}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="ID: " />
<TextBlock Text="{Binding ID}" />
</StackPanel>
</StackPanel>
<Button Grid.Column="2" Content="{Binding Status}" Command="{Binding CompleteCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MainPageViewModel}}}" CommandParameter="{Binding}" HorizontalAlignment="Right" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I need my CommandParameter be the ListItem of this ListBox.
Set the AncestorType to ListBox and include DataContext in the path:
<Button ... Command="{Binding DataContext.CompleteCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}" CommandParameter="{Binding}" HorizontalAlignment="Right"></Button>
Then the Command binding should work provided that the CompleteCommand property belongs to the same class as the Items property
Below is my xaml
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="2*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="2*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ListBox x:Name="movieList" ItemsSource="{Binding Path=MovieMain.Movies}" Margin="10">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Name}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<StackPanel Grid.Column="1" Margin="10">
<StackPanel Orientation="Horizontal">
<Label Content="Selected movie: " Margin="2" />
<Label Content="{Binding Path=SelectedItem.Name, ElementName=movieList}" />
</StackPanel>
<igDP:XamDataGrid x:Name="dataGrid" DataSource="{Binding Path=SelectedItem.Artists, ElementName=movieList}">
<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout>
<igDP:ComboBoxField Name="Name">
<igDP:ComboBoxField.EditorStyle>
<Style TargetType="igEditors:XamComboEditor">
<Setter Property="ItemsSource"
Value="{Binding Path=DataContext.ComboItems, RelativeSource={RelativeSource AncestorType={x:Type igDP:XamDataGrid}}}" />
</Style>
</igDP:ComboBoxField.EditorStyle>
</igDP:ComboBoxField>
<igDP:NumericField Name="Age" />
</igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>
</StackPanel>
<Button Grid.Row="1" Grid.Column="0" Width="55" Height="25" Command="{Binding ClickCommand}"/>
</Grid>
In above I bind Listbox with one model and based on selected item I am binding datagrid.
Now I am doing delete operation on datagrid. So how can I achieve the delete functionality?
I created a button for deleteing records. Can we pass command parameter for sleeted row?
Try this:
<Button ... Command="{Binding ClickCommand}"
CommandParameter="{Binding SelectedDataItems[0], ElementName=dataGrid}" />
I'm working with a WPF application to manage our main software's versions. This application has a ListBox, and I set the ListBox.DataTemplate to each ListBoxItem has a Label and 2 Buttons inside it.
The following code shows my ListBox code:
<ListBox Grid.Row="0" SelectedItem="{Binding Path=SelectedVersion}" ItemsSource="{Binding Path=PatchList, Mode=TwoWay}" d:DataContext="{d:DesignInstance {x:Type ViewModels:MainWindowViewModel}}"
SelectionMode="Single" IsSynchronizedWithCurrentItem="True" Margin="1" ScrollViewer.HorizontalScrollBarVisibility="Disabled" SelectedIndex="0">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Content="{Binding Path=VersionNumber}" HorizontalAlignment="Left" Foreground="#FFFFFF" FontSize="19" />
<Button Grid.Column="1" Width="25" Height="25" Template="{StaticResource OnMouseOverListBoxitem}" ToolTip="Release" Command="{Binding Path=DataContext.ReleaseVersionCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}" HorizontalAlignment="Right" d:DataContext="{d:DesignInstance {x:Type ViewModels:MainWindowViewModel}}" CommandParameter="{Binding}">
<ContentControl Template="{StaticResource Release}" />
</Button>
<Button Grid.Column="2" Width="25" Height="25" Template="{StaticResource OnMouseOverListBoxitem}" ToolTip="Trash" Command="{Binding Path=DataContext.DeleteVersionCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}" HorizontalAlignment="Right" d:DataContext="{d:DesignInstance {x:Type ViewModels:MainWindowViewModel}}" CommandParameter="{Binding}">
<ContentControl Template="{StaticResource Trash}" />
</Button>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
The problem is that I would like to show the label and the buttons ONLY for the Selected ListBoxItem.
By the way, I'm using bindings, and if you see some different code it's because I'm also using MahApp.Metro for Windows8-style.
Any suggestions?
Thank you.
try this one.
<Window.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter1" />
</Window.Resources>
<Grid>
<ListBox ItemsSource="{Binding Fnts}" Grid.Row="0" SelectedItem="{Binding Path=SelectedVersion}"
SelectionMode="Single" IsSynchronizedWithCurrentItem="True" Margin="1" ScrollViewer.HorizontalScrollBarVisibility="Disabled" SelectedIndex="0">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Label Content="{Binding}" />
<Button Content=" X " Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}, Path=IsSelected, Converter={StaticResource BooleanToVisibilityConverter1}}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
Hi. I'm running into issues with having a RadExpander in a RadListBox. Basically, I have exactly something like here or here.
I have a OneWayToSource binding, but I want the binding to happen only when the RadExpander is expanded and not when it is collapsed.
Is there a way I can conditionally bind the two UI Elements?
EDIT: (Sample code which makes some of the downvoters happy)
<DataTemplate x:Key="ListBoxItemTemplate" DataType="{x:Type telerik:RadListBoxItem}">
<!--<DataTemplate.Triggers>
<DataTrigger Binding="{Binding ElementName=listExpander, Path=IsExpanded, Mode=TwoWay}" Value="True">
<Setter Property="IsSelected" Value="True" />
</DataTrigger>
</DataTemplate.Triggers>-->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<telerik:RadExpander x:Name="listExpander"
IsExpanded="{Binding Mode=TwoWay, IsAsync=True, Path=IsSelected, RelativeSource={RelativeSource AncestorType=telerik:RadListBoxItem, Mode=FindAncestor}}"
VerticalContentAlignment="Top" ToolTip="Double click on the List name to edit it">
<telerik:RadExpander.Header>
<Grid>
<TextBlock x:Name="listNameCaption" MouseDown="listName_txtblk_MouseDown"
Text="{Binding ListName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource HighlightedDetailsStyleForTextBlock}" />
<TextBox LostFocus="listName_txtbox_LostFocus" Visibility="Collapsed"
Text="{Binding ListName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Style="{StaticResource HighlightedDetailsStyleForTextBox}" />
</Grid>
</telerik:RadExpander.Header>
<telerik:RadExpander.Content>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Border BorderBrush="#FFDADADA" BorderThickness="0,0,1,1" MinHeight="20" MinWidth="200" CornerRadius="3" Margin="5">
<Border BorderBrush="#B2ADBDD1" BorderThickness="1" CornerRadius="2">
<StackPanel>
<StackPanel Orientation="Horizontal">
<Label FontFamily="Segoe UI" FontSize="11" Content="List Type:" FontStyle="Italic" />
<Label FontFamily="Segoe UI" FontSize="11" Content="{Binding ListType}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label FontFamily="Segoe UI" FontSize="11" Content="Tree:" FontStyle="Italic" />
<Label FontFamily="Segoe UI" FontSize="11" Content="{Binding TreeName}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label FontFamily="Segoe UI" FontSize="11" Content="Discount Date:" FontStyle="Italic" />
<Label FontFamily="Segoe UI" FontSize="11" Content="{Binding DiscountDate}" />
</StackPanel>
</StackPanel>
</Border>
</Border>
</Grid>
</telerik:RadExpander.Content>
<!--<telerik:RadExpander.Style>
<Style TargetType="{x:Type telerik:RadExpander}">
<Style.Triggers>
<Trigger Property="IsExpanded" Value="True">
<Setter Property="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem, Mode=FindAncestor}, Path=IsSelected}" Value="True"/>
</Trigger>
</Style.Triggers>
</Style>
</telerik:RadExpander.Style>-->
</telerik:RadExpander>
</Grid>
</DataTemplate>
<telerik:RadListBox x:Name="allListBox"
Style="{StaticResource ListBoxStyle}"
ItemsSource="{Binding Lists, Mode=TwoWay}"
ItemTemplate="{StaticResource ListBoxItemTemplate}"
SelectedItem="{Binding SelectedListItem, Mode=TwoWay}">
<telerik:RadListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</telerik:RadListBox.ItemsPanel>
</telerik:RadListBox>
EDIT 2:
Fixed it, but from code behind. Wish there was a cleaner way where we could just say: "RadExpander - you bind to RadListBoxItem's IsSelected property only if you have IsExpanded=True" from XAML.
This is the work-around code:
private void ListItemExpanded(object sender, RadRoutedEventArgs e)
{
var listItem = sender as RadExpander;
if(listItem == null)
return;
if (!listItem.IsExpanded) return;
var parent = VisualTreeHelper.GetParent(listItem);
while (parent != null && !(parent is RadListBoxItem))
{
parent = VisualTreeHelper.GetParent(parent);
}
if(parent == null)
return;
var listBoxItem = parent as RadListBoxItem;
if (!listBoxItem.IsSelected)
listBoxItem.IsSelected = true;
}
and
<telerik:RadExpander x:Name="listExpander" Expanded="ListItemExpanded" VerticalContentAlignment="Top" ToolTip="Double click on the List name to edit it">
Solution 1. React to the expand events and change the binding of your element through code.
Solution 2: Use MultiBinding and IMultiValueConverter: http://www.switchonthecode.com/tutorials/wpf-tutorial-using-multibindings
Depending on bound item - I use different data templates to display data. Now I also need to modify behavior/style of treeview itself. Is it possible to switch style for items depending on object property? Right now it's only one specified: ItemContainerStyle="{StaticResource TreeViewItemStyleFolder}"
I would like to create second style TreeViewItemStyleDocument
Current XAML (with custom style and template selector)
<sdk:TreeView ItemsSource="{Binding Items}"
Grid.Row="1"
Style="{StaticResource TreeViewStyle1}"
ItemContainerStyle="{StaticResource TreeViewItemStyleFolder}"
>
<sdk:TreeView.ItemTemplate>
<sdk:HierarchicalDataTemplate ItemsSource="{Binding SubItems}">
<DocumentManagement:DocumentTreeViewItemTemplateSelector
Content="{Binding}">
<DocumentManagement:DocumentTreeViewItemTemplateSelector.FolderTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="24" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<!-- FOLDER ICON AND CAPTION -->
<Image Source="{Binding IconSource}" Width="24" Height="24" />
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Left"
Grid.Column="1" Margin="5,0"
Text="{Binding Folder.FolderId}" FontSize="12" Foreground="#2C2C2C" />
</Grid>
</DataTemplate>
</DocumentManagement:DocumentTreeViewItemTemplateSelector.FolderTemplate>
<DocumentManagement:DocumentTreeViewItemTemplateSelector.DocumentTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="24" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="1" Orientation="Horizontal">
<TextBlock FontSize="10" Foreground="#2C2C2C">
<Run Text="Added by" />
<Run Text="{Binding Document.MEMUser.UserName}" />
<Run Text=" on " />
<Run Text="{Binding CreatedOn, Converter={StaticResource DateTimeToStringConverter}}" />
</TextBlock>
<!--BIND COMMANDS TO PARENT ViewModel to process operations-->
<Button Content="Delete" Command="{Binding DataContext.DeleteCommand, ElementName=LayoutRoot}" CommandParameter="{Binding}" />
<Button Content="Download" Command="{Binding DataContext.DownloadCommand, ElementName=LayoutRoot}" CommandParameter="{Binding}" />
</StackPanel>
</Grid>
</DataTemplate>
</DocumentManagement:DocumentTreeViewItemTemplateSelector.DocumentTemplate>
</DocumentManagement:DocumentTreeViewItemTemplateSelector>
</sdk:HierarchicalDataTemplate>
</sdk:TreeView.ItemTemplate>
</sdk:TreeView>
EDIT:
Added triggers to switch ItemContainerStyle based on property but I think problem is that I'm using hieratchical data template. If I put breakpoint on IsFolder property - there is no source object.
<sdk:TreeView x:Name="DocumentsTreeView" ItemsSource="{Binding Items}"
Grid.Row="1"
Style="{StaticResource TreeViewStyleTransparent}">
<!-- ItemContainerStyle="{StaticResource TreeViewItemStyleFolders}"-->
<i:Interaction.Triggers>
<ei:DataTrigger Value="False" Binding="{Binding IsFolder}">
<ei:ChangePropertyAction TargetName="DocumentTreeView" PropertyName="ItemContainerStyle"
Value="{StaticResource TreeViewItemStyleFolders}" />
</ei:DataTrigger>
<ei:DataTrigger Value="True" Binding="{Binding IsFolder}">
<ei:ChangePropertyAction TargetName="DocumentTreeView" PropertyName="ItemContainerStyle"
Value="{StaticResource TreeViewItemStyleDocuments}" />
</ei:DataTrigger>
</i:Interaction.Triggers>
<sdk:TreeView.ItemTemplate>
<sdk:HierarchicalDataTemplate ItemsSource="{Binding SubItems}">
<DocumentManagement:DocumentTreeViewItemTemplateSelector
Content="{Binding}">
<DocumentManagement:DocumentTreeViewItemTemplateSelector.FolderTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="24" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<!-- FOLDER ICON AND CAPTION -->
<Image Source="{Binding IconSource}" Width="24" Height="24" />
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Left"
Grid.Column="1" Margin="5,0"
Text="{Binding Folder.FolderId}" FontSize="12" Foreground="#2C2C2C" />
</Grid>
</DataTemplate>
</DocumentManagement:DocumentTreeViewItemTemplateSelector.FolderTemplate>
<DocumentManagement:DocumentTreeViewItemTemplateSelector.DocumentTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="24" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="1" Orientation="Horizontal">
<TextBlock FontSize="10" Foreground="#2C2C2C">
<Run Text="Added by" />
<Run Text="{Binding Document.MEMUser.UserName}" />
<Run Text="on" />
<Run Text="{Binding Document.CreatedOn, Converter={StaticResource DateTimeToStringConverter}}" />
</TextBlock>
<!--BIND COMMANDS TO PARENT ViewModel to process operations-->
<Button Content="Delete" Command="{Binding DataContext.DeleteCommand, ElementName=LayoutRoot}" CommandParameter="{Binding}" />
<Button Content="Download" Command="{Binding DataContext.DownloadCommand, ElementName=LayoutRoot}" CommandParameter="{Binding}" />
</StackPanel>
</Grid>
</DataTemplate>
</DocumentManagement:DocumentTreeViewItemTemplateSelector.DocumentTemplate>
</DocumentManagement:DocumentTreeViewItemTemplateSelector>
</sdk:HierarchicalDataTemplate>
</sdk:TreeView.ItemTemplate>
</sdk:TreeView>
If I understand correctly you want style to change dynamically based on a property value and you want this to be performed globally on everyitems on the page referencing the given style?
If that is the case I would suggest you looking into storyboards and states within Expression Blend. I do not see you mentioning Blend in your description. Are you using it? The treeview has many items that can be customized and some that are harder. I had an issue last week that my hyperlinks that were nested within a treeview could not effectively change the font color. I would probably been able to do it spending more time on the design but I changed the design intent instead.
The preview version of Blend for Silverlight 5 is free until June 2013 according to my install.
http://www.microsoft.com/en-us/download/details.aspx?id=9503
Good luck,