Hi,
I need help in loading and controlling RadPanelBar programatically in MVVM pattern start from loading the panelBarItems.
I want to create a RadPanelBar which will have set of items and each item will have the ContentControl (loads an UserControl). I want to control the expand and selection of each item by set of buttons. Let me explain this briefly,
my RadPanelBar has 3 items, each PanelBarItem loads an usercontrol. I should be able to control expand of these panelbar items by a listbox having 3 buttons i.e. 1st RadPanelBar item expands on 1st button click, 2nd item expands on 2nd button click etc.
I should be able to do everything progrmatically i.e. even loading the panelbar items and List box items.
I am attaching the XAML code i have used to achieve this,
Here is the view model code,
I hope you understand what i want to achieve.
Let me know if you need more information.
I need help in loading and controlling RadPanelBar programatically in MVVM pattern start from loading the panelBarItems.
I want to create a RadPanelBar which will have set of items and each item will have the ContentControl (loads an UserControl). I want to control the expand and selection of each item by set of buttons. Let me explain this briefly,
my RadPanelBar has 3 items, each PanelBarItem loads an usercontrol. I should be able to control expand of these panelbar items by a listbox having 3 buttons i.e. 1st RadPanelBar item expands on 1st button click, 2nd item expands on 2nd button click etc.
I should be able to do everything progrmatically i.e. even loading the panelbar items and List box items.
I am attaching the XAML code i have used to achieve this,
<
telerik:RadPanelBar
x:Name
=
"mybar"
Width
=
"830"
Height
=
"430"
HorizontalAlignment
=
"Left"
Grid.Row
=
"0"
Focusable
=
"False"
VerticalAlignment
=
"Stretch"
BorderBrush
=
"#FFCBD8E8"
BorderThickness
=
"1 1 0 1"
ExpandMode
=
"Multiple"
Margin
=
"10,10,10,10"
Background
=
"Transparent"
ItemsSource
=
"{Binding PanelBarItemsList}"
SelectedItem
=
"{Binding PanelBarSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
>
<
telerik:RadPanelBar.ItemTemplate
>
<
DataTemplate
>
<
telerik:RadPanelBarItem
x:Name
=
"pnliTopic"
IsSelected
=
"{Binding IsSelectedValue, Mode=TwoWay}"
IsExpanded
=
"{Binding IsExpandedValue, Mode=TwoWay}"
>
<
telerik:RadPanelBarItem.Header
>
<
TextBlock
Text
=
"{Binding Name}"
/>
</
telerik:RadPanelBarItem.Header
>
<
ContentControl
x:Name
=
"View"
Margin
=
"10,10,10,10"
Visibility
=
"Visible"
HorizontalAlignment
=
"Left"
VerticalAlignment
=
"Top"
Width
=
"Auto"
Height
=
"Auto"
Content
=
"{Binding UserControlView}"
/>
</
telerik:RadPanelBarItem
>
</
DataTemplate
>
</
telerik:RadPanelBar.ItemTemplate
>
</
telerik:RadPanelBar
>
Here is the view model code,
private
ObservableCollection<ToolOption> m_PanelBarItems;
public
ObservableCollection<ToolOption> SettingsList
{
get
{
return
m_PanelBarItems; }
set
{
m_PanelBarItems = value;
}
}
Contructor()
{
m_PanelBarItems =
new
ObservableCollection<PanelBarItem>();
foreach
(
string
strTool
in
m_LocalCollection)
{
PanelBarItem item=
new
ToolOption(strTool );
m_PanelBarItems.Add(item);
}
m_PanelBarItems[0].IsExpandedvalue = true;
m_PanelBarItems[0].IsSelectedValue = true;
m_PanelBarItems[0].UserControlView = new UserControlView1();
PanelBarSelected = m_PanelBarItems[0];
m_PanelBarItems[0].UserControlView.Visibility = Visibility.Visible;
this.OnPropertyChanged("PanelBarSelectTool");
}
public object PanelBarSelectTool { get; set; }
//PanelBarItem Class definition
public
class
PanelBarItem: INotifyPropertyChanged
{
public
string
Name {
get
;
set
; }
private
bool
selected;
private
bool
expanded;
public
System.Windows.Controls.ContentControl m_View =
null
;
//private object m_View = null;
public
bool
IsSelectedValue
{
get
{
return
selected;
}
set
{
selected = value;
this
.OnPropertyChanged(
"IsSelectedValue"
);
}
}
public
bool
IsExpandedvalue
{
get
{
return
expanded;
}
set
{
expanded = value;
this
.OnPropertyChanged(
"IsExpandedvalue"
);
}
}
public
System.Windows.Controls.ContentControl UserControlView
{
get
{
return
m_View;
}
set
{
if
(m_View != value)
{
m_View = value;
}
}
}
public
PanelBarItem(
string
name)
{
this
.Name = name;
this
.IsSelectedValue =
false
;
this
.IsExpandedvalue =
false
;
}
public
event
PropertyChangedEventHandler PropertyChanged;
private
void
OnPropertyChanged(
string
propertyName)
{
if
(
this
.PropertyChanged !=
null
)
{
this
.PropertyChanged(
this
,
new
PropertyChangedEventArgs(propertyName));
}
}
}
I hope you understand what i want to achieve.
Let me know if you need more information.