So I have a dynamic RadGridView using MVVM and Caliburn Micro. This means that I add Columns programmatically to the control. basically like this:
for (int i = 0; i < length; i++)
{
Binding b = new Binding(string.Format("Collection[{0}].ValueIWant", i));
binding.StringFormat = "{0:0.##}";
GridViewDataColumn column = new GridViewDataColumn()
{
Header = HeaderFor(i),
DataMemberBinding = b,
DataType = typeof(double?)
};
Control.columns.Add(column);
}
Now I need to add new lines that show the percentage between line 1 and 2
, 2 and 3
and so on.
I've managed to do that but I'm not sure how I would manage to change the String.format specifically for those cells instead of the whole column.
CellTemplateSelector came to mind but I'm not sure that is a good idea as this might mean I have to set the binding again, not knowing the value of i
and such. Also I only want to change the string.format on the binding.
As I'm manipulating the number as a double (0,5 is 50%, 50 is 5000%) I guess I have to mask the input as well. not sure if String.Format does that for me as well or if I should use RadMaskedInput
RadContextMenu
with Icon, I am using dynamic binding to observable collection, which contains context menu items (Text and Icon), I am following this tutorial "Dynamic Binding", following is my XAML.<
Style
x:Key
=
"MenuItemStyle"
TargetType
=
"{x:Type telerik:RadMenuItem}"
>
<
Setter
Property
=
"Icon"
>
<
Setter.Value
>
<
Image
Source
=
"{Binding IconPath, Converter={StaticResource pathtoimage}}"
/>
</
Setter.Value
>
</
Setter
>
</
Style
>
<
HierarchicalDataTemplate
x:Key
=
"MenuItemTemplate"
>
<
telerik:RadButton
Content
=
"{Binding Title}"
HorizontalContentAlignment
=
"Left"
Background
=
"Transparent"
BorderBrush
=
"Transparent"
/>
</
HierarchicalDataTemplate
>
<
telerik:RadGridView
x:Name
=
"myGridView"
AutoGenerateColumns
=
"False"
ItemsSource
=
"{Binding GridData}"
VerticalAlignment
=
"Top"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Result}"
Header
=
"Result"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Category}"
Header
=
"Category"
/>
</
telerik:RadGridView.Columns
>
<
telerik:RadContextMenu.ContextMenu
>
<
telerik:RadContextMenu
ItemsSource
=
"{Binding ContextMenuItems}"
ItemContainerStyle
=
"{StaticResource MenuItemStyle}"
ItemTemplate
=
"{StaticResource MenuItemTemplate}"
>
</
telerik:RadContextMenu
>
class MainViewModel
{
private ObservableCollection<
MenuItemObj
> menuitems_;
public ObservableCollection<
MenuItemObj
> ContextMenuItems
{
get
{
return menuitems_;
}
set
{
menuitems_ = value;
}
}
private ObservableCollection<
GridRowDataObj
> griddata_;
public ObservableCollection<
GridRowDataObj
> GridData
{
get
{
return griddata_;
}
set
{
griddata_ = value;
}
}
}
public class MenuItemObj
{
public string Title { get; set; }
public string IconPath { get; set; }
}
public class GridRowDataObj
{
public string Result { set; get; }
public string Category { set; get; }
}
//TODO
ObservableCollection<
GridRowDataObj
> gd = new ObservableCollection<
GridRowDataObj
>();
gd.Add(new GridRowDataObj() { Result = "Matric", Category = "SSC" });
gd.Add(new GridRowDataObj() { Result = "FSc", Category = "HSSC" });
gd.Add(new GridRowDataObj() { Result = "FA", Category = "HSSC" });
//TODO
ObservableCollection<
MenuItemObj
> mi = new ObservableCollection<
MenuItemObj
>();
mi.Add(new MenuItemObj() { Title = "My Item 1", IconPath = "/Images/item1.png" });
mi.Add(new MenuItemObj() { Title = "My Item 2", IconPath = "/Images/item2.png" });
mi.Add(new MenuItemObj() { Title = "My Item 3", IconPath = "/Images/item3.png" });
MainViewModel mvm = new MainViewModel();
mvm.ContextMenuItems = mi;
mvm.GridData = gd;
this.DataContext = mvm;
<telerik:RadPaneGroup FontSize="26" >
<telerik:RadPane x:Name="_outputControl" CanUserClose="True" Header="Output" >
<ContentControl Grid.Row="0" regions:RegionManager.RegionName="OutputRegion" />
</telerik:RadPane>
</telerik:RadPaneGroup>
Second :<Window.Resources>Nothing work, Is there a way to change the font size?
<Style x:key="headerStyle" TargetType="telerik:RadPaneGroup" BasedOn="{StaticResource {telerik:ThemeResourceKey ThemeType=telerik:MetroTheme, ElementType=telerik:RadPaneGroup}}">
<Setter Property="FontSize" Value="26"/>
</Style>
</Window.Resources><telerik:RadPaneGroup Style="{StaticResource headerStyle}">
<telerik:RadPane x:Name="_outputControl" CanUserClose="True" Header="Output" >
<ContentControl Grid.Row="0" regions:RegionManager.RegionName="OutputRegion" />
</telerik:RadPane>
</telerik:RadPaneGroup>
Regards.