private ObservableCollection<
Bundle
> _availableProductBundles;
public ObservableCollection<
Bundle
> AvailableProductBundles
{
get
{
return _availableProductBundles;
}
set
{
_availableProductBundles = value;
RaisePropertyChanged(PropertyNames.AVAILABLE_PRODUCT_BUNDLES);
}
}
private void LoadAvailableBundle(PortableBundleCatalog pbc)
{
AvailableProductBundles = new ObservableCollection<
Bundle
>();
Bundle b;
Channel c;
string strBundleName = string.Empty;
string strChannelName = string.Empty;
foreach (PortableBundle pBundle in pbc.Bundles)
{
//strBundleName = pBundle.BundleName;
strBundleName = pBundle.Product;
strChannelName = pBundle.Name;
if (_availableProductBundles.Count != 0)
{
var containsBundleName = AvailableProductBundles.Where(X => X.BName == strBundleName).FirstOrDefault();
if (containsBundleName != null)
{
c = new Channel(strChannelName);
containsBundleName.Channels.Insert(containsBundleName.Channels.Count, c);
}
else
{
b = new Bundle(strBundleName);
c = new Channel(strChannelName);
b.Channels.Add(c);
AvailableProductBundles.Add(b);
}
}
else
{
b = new Bundle(strBundleName);
c = new Channel(strChannelName);
b.Channels.Add(c);
_availableProductBundles.Add(b);
}
}
}
Bundle.cs
using System.Collections.ObjectModel;
using Telerik.Windows.Controls;
namespace WMCustomizationTool.Model
{
public class Bundle
{
public Bundle(string strBName)
{
this.BName = strBName;
this.Channels = new ObservableCollection<
Channel
>();
}
private string _bundleName;
public string BName
{
get
{
return _bundleName;
}
set
{
_bundleName = value;
}
}
private ObservableCollection<
Channel
> _channels;
public ObservableCollection<
Channel
> Channels
{
get
{
return _channels;
}
set
{
_channels = value;
}
}
private bool _isEnabled = true;
public bool isEnabled
{
get
{
return _isEnabled;
}
set
{
_isEnabled = value;
}
}
private bool _isExpanded;
public bool isExpanded
{
get
{
return _isExpanded;
}
set
{
_isExpanded = value;
}
}
}
}
Channel.cs
using System;
using Telerik.Windows.Controls;
namespace WMCustomizationTool.Model
{
public class Channel
{
public Channel(string strCName)
{
this.CName = strCName;
}
private string _channelName;
public string CName
{
get
{
return _channelName;
}
set
{
_channelName = value;
}
}
}
}
private void EnableOrDisableBundlesForSelectedPackage(PortableBundle portableBundle, bool mode)
{
foreach (Bundle bb in AvailableProductBundles)
{
foreach (Channel cc in bb.Channels)
{
if (cc.CName == portableBundle.Name)
{
bb.isEnabled = false; --------------------------------> doing this is NOT disabling my the treeviewItem
}
}
}
}
<
UserControl
x:Class
=
"WMCustomizationTool.View.PackageEditorAvailableBundlesView"
xmlns:data
=
"clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
xmlns:view
=
"clr-namespace:WMCustomizationTool.View"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
mc:Ignorable
=
"d"
d:DesignHeight
=
"300"
d:DesignWidth
=
"400"
>
<
UserControl.Resources
>
<
ResourceDictionary
>
<
ResourceDictionary.MergedDictionaries
>
<
ResourceDictionary
Source
=
"/WMCustomizationTool;component/Resources/WMCustomizationToolTheme.xaml"
/>
</
ResourceDictionary.MergedDictionaries
>
<
Style
x:Key
=
"RADTreeViewItemStyle"
TargetType
=
"telerik:RadTreeViewItem"
>
<
Setter
Property
=
"HorizontalAlignment"
Value
=
"Left"
/>
<
Setter
Property
=
"CheckState"
Value
=
"Off"
/>
<
Setter
Property
=
"BorderThickness"
Value
=
"1"
/>
<
Setter
Property
=
"Padding"
Value
=
"1 0 5 0"
/>
<
Setter
Property
=
"IsDropAllowed"
Value
=
"True"
/>
<
Setter
Property
=
"ItemsOptionListType"
Value
=
"Default"
/>
<
Setter
Property
=
"IsEnabled"
Value
=
"True"
/>
<
Setter
Property
=
"MinHeight"
Value
=
"24"
/>
<
Setter
Property
=
"Template"
Value
=
"{StaticResource TreeViewItemDefaultTemplate}"
/>
<
Setter
Property
=
"ItemsPanel"
>
<
Setter.Value
>
<
ItemsPanelTemplate
>
<
telerik:TreeViewPanel
VerticalAlignment
=
"Bottom"
/>
</
ItemsPanelTemplate
>
</
Setter.Value
>
</
Setter
>
</
Style
>
<
telerik:ContainerBindingCollection
x:Name
=
"BindingsCollections"
>
<
telerik:ContainerBinding
PropertyName
=
"IsEnabled"
Binding
=
"{Binding isEnabled, Mode=TwoWay}"
/>
<
telerik:ContainerBinding
PropertyName
=
"IsExpanded"
Binding
=
"{Binding isExpanded, Mode=TwoWay}"
/>
</
telerik:ContainerBindingCollection
>
<
telerik:HierarchicalDataTemplate
x:Key
=
"ChannelTemplate"
telerik:ContainerBinding.ContainerBindings
=
"{StaticResource BindingsCollections}"
>
<
TextBlock
Text
=
"{Binding CName}"
/>
</
telerik:HierarchicalDataTemplate
>
<
telerik:HierarchicalDataTemplate
x:Key
=
"BundleTemplate"
ItemTemplate
=
"{StaticResource ChannelTemplate}"
ItemsSource
=
"{Binding Channels}"
telerik:ContainerBinding.ContainerBindings
=
"{StaticResource BindingsCollections}"
>
<
TextBlock
Text
=
"{Binding BName}"
/>
</
telerik:HierarchicalDataTemplate
>
</
ResourceDictionary
>
</
UserControl.Resources
>
<
Grid
x:Name
=
"LayoutRoot"
>
<
Grid
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"*"
/>
</
Grid.RowDefinitions
>
<
telerik:RadTreeView
x:Name
=
"BundlesLocationsView_RadTreeView"
VerticalAlignment
=
"Stretch"
ItemContainerStyle
=
"{StaticResource RADTreeViewItemStyle}"
SelectionMode
=
"Single"
IsExpandOnSingleClickEnabled
=
"True"
ScrollViewer.VerticalScrollBarVisibility
=
"Auto"
ItemTemplate
=
"{StaticResource BundleTemplate}"
ItemsSource
=
"{Binding Path=AvailableProductBundles, Mode=TwoWay}"
>
</
telerik:RadTreeView
>
</
Grid
>
</
Grid
>
</
UserControl
>
Here is the scenario I have. I have a tree populated with one parent node with multiple child node.
Say for (e.g) - A, B, C are the parent node. A1, A2, B1, B2, C1, C2 are its respective children.
There is a combo box populated with value. Each value has ONE or MORE children stated above (A1, A2, B1, B2, C1, C2).
So, when I select a value from the combobox, the treeview that has the respective node (including parent) should be disabled.
Say for(e.g) If the value in the combobox has "A1" then the treeview of "A -A1, A2" should be disabled.
I am doing this using "HierarchicalDataTemplate".
But I could not get the Tree to disable a particular Parent or child item.
Pasting code that I have for XAML and View Model and Model declaration.
Please do help me.