Hi everyone,
I'm having some trouble setting the data context property of my ContentTemplate within my RadTabControl (a tab control by Telerik). Here is my XAML:
<telerik:RadTabControl Grid.Row="1" TabOrientation="Horizontal" ItemsSource="{Binding Counterparties}">
<telerik:RadTabControl.ContentTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!--<telerik:RadGridView Grid.Row="0" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.ConsolidatedPositions}" Name="ExposureView" VerticalAlignment="Stretch" AutoGenerateColumns="False" CanUserDeleteRows="False" CanUserInsertRows="False" IsTabStop="False" RowHeight="18" SelectionMode="Extended" SelectionUnit="Mixed" IsReadOnly="True" ShowGroupPanel="False" ColumnWidth="75" GroupRenderMode="Flat" CanUserSortGroups="False" CanUserSortColumns="True" FontSize="11" RowIndicatorVisibility="Collapsed">-->
<telerik:RadGridView Grid.Row="0" ItemsSource="{Binding Path=DataContext.ConsolidatedPositions}" Name="ExposureView" VerticalAlignment="Stretch" AutoGenerateColumns="False" CanUserDeleteRows="False" CanUserInsertRows="False" IsTabStop="False" RowHeight="18" SelectionMode="Extended" SelectionUnit="Mixed" IsReadOnly="True" ShowGroupPanel="False" ColumnWidth="75" GroupRenderMode="Flat" CanUserSortGroups="False" CanUserSortColumns="True" FontSize="11" RowIndicatorVisibility="Collapsed">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn Header="Cusip" DataMemberBinding="{Binding Path=Cusip, Mode=OneWay}"/>
<telerik:GridViewDataColumn Header="Description" DataMemberBinding="{Binding Path=Description, Mode=OneWay}" Width="150" />
<telerik:GridViewDataColumn Header="Par Net" DataMemberBinding="{Binding Path=ParNet, Mode=OneWay}" DataFormatString="N0" TextAlignment="Right" Width="100" CellStyleSelector="{StaticResource ParNetStyleSelector}"/>
<telerik:GridViewDataColumn Header="Dirty Price" DataMemberBinding="{Binding Path=Price, Mode=OneWay}" Width="80" DataFormatString="F3" TextAlignment="Right"/>
<telerik:GridViewDataColumn Header="Settled Position" DataMemberBinding="{Binding Path=SettledPosition, Mode=OneWay}" DataFormatString="N0" TextAlignment="Right" Width="105" CellStyleSelector="{StaticResource SettledPositionStyleSelector}"/>
<telerik:GridViewDataColumn Header="Repos/Reverse" DataMemberBinding="{Binding Path=Repos, Mode=OneWay}" DataFormatString="N0" TextAlignment="Right" Width="90" CellStyleSelector="{StaticResource ReposStyleSelector}" />
<telerik:GridViewDataColumn Header="Clean Market Net" DataMemberBinding="{Binding Path=CleanMarketNet, Mode=OneWay}" TextAlignment="Right" DataFormatString="N0" Width="120" CellStyleSelector="{StaticResource CleanMarketNetStyleSelector}" />
<telerik:GridViewDataColumn Header="Borrows/Lent" DataMemberBinding="{Binding Path=TotalBorrows, Mode=OneWay}" TextAlignment="Right" DataFormatString="N0" Width="100" CellStyleSelector="{StaticResource TotalBorrowStyleSelector}"/>
<telerik:GridViewDataColumn Header="Pledge In/Out" DataMemberBinding="{Binding Path=TotalPledges, Mode=OneWay}" Width="100" TextAlignment="Right" DataFormatString="N0" CellStyleSelector="{StaticResource TotalPledgesStyleSelector}"/>
<telerik:GridViewDataColumn Header="T+1 Net Pos" DataMemberBinding="{Binding Path=FutureNet1, Mode=OneWay}" Width="90" TextAlignment="Right" DataFormatString="N0" CellStyleSelector="{StaticResource FutureNet1StyleSelector}"/>
<telerik:GridViewDataColumn Header="T+2 Net Pos" DataMemberBinding="{Binding Path=FutureNet2, Mode=OneWay}" Width="90" TextAlignment="Right" DataFormatString="N0" CellStyleSelector="{StaticResource FutureNet2StyleSelector}"/>
<telerik:GridViewDataColumn Header="T+3 Net Pos" DataMemberBinding="{Binding Path=FutureNet3, Mode=OneWay}" Width="90" TextAlignment="Right" DataFormatString="N0" CellStyleSelector="{StaticResource FutureNet3StyleSelector}"/>
</telerik:RadGridView.Columns>
<telerik:RadGridView.InputBindings>
<KeyBinding Key="F2" Command="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ClearGridFiltersCommand}"></KeyBinding>
<!--<KeyBinding Key="F2" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.ClearGridFiltersCommand}" CommandParameter="{Binding ElementName=ExposureView}"></KeyBinding>-->
</telerik:RadGridView.InputBindings>
</telerik:RadGridView>
<StatusBar Grid.Row="1">
<StatusBar.ItemsPanel>
<ItemsPanelTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="200" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="50" />
</Grid.ColumnDefinitions>
</Grid>
</ItemsPanelTemplate>
</StatusBar.ItemsPanel>
<StatusBarItem Grid.Column="0">
<Label Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.Status}" Foreground="White"/>
</StatusBarItem>
<Separator Grid.Column="1" />
<StatusBarItem Grid.Column="2" >
<StackPanel Orientation="Horizontal">
<Label Content="Last Update:" Foreground="White" />
<Label Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.LastUpdate}" Foreground="White"/>
</StackPanel>
</StatusBarItem>
<Separator Grid.Column="3"/>
<StatusBarItem Grid.Column="4" HorizontalAlignment="Right">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<!--<Label Content="NET Pledged: " Foreground="White"></Label>-->
<!--<Label Content="{Binding NetPledged}" ContentStringFormat="{}{0:N0}" FontWeight="Bold" Foreground="{Binding Path=NetPledged, Converter={StaticResource RedNegativeLabelForegroundConverter}}"></Label>-->
<Label Content="Market Value Borrowed: " Foreground="White"/>
<Label Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.TotalParNet}" ContentStringFormat="{}{0:N0}" FontWeight="Bold" Foreground="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.TotalParNet, Converter={StaticResource RedNegativeLabelForegroundConverter}}"/>
<Label Content="Market Value Pledged: " Foreground="White"/>
<Label Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.TotalMarketValue}" ContentStringFormat="{}{0:N0}" FontWeight="Bold" Foreground="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.TotalMarketValue, Converter={StaticResource RedNegativeLabelForegroundConverter}}"/>
</StackPanel>
</StatusBarItem>
<Separator Grid.Column="5" />
<StatusBarItem Grid.Column="6" HorizontalAlignment="Right">
<Label Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.RecordCount}" Foreground="White"/>
</StatusBarItem>
</StatusBar>
</Grid>
</DataTemplate>
</telerik:RadTabControl.ContentTemplate>
</telerik:RadTabControl>
I'm using MVVM Light. The Counterparties' data context is my VM called MainViewModel. I want the ItemsSource of my GridView to be a different property of my ViewModel, called ConsolidatedPositions. So I want the RadGridView's DataContext to be the VM, **NOT** the collection of Counterparties, which it is currently doing.
I've found a temporary solution, but it is SLOW:
<!--<telerik:RadGridView Grid.Row="0" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}
My Windows DataContext:
DataContext="{Binding Main, Source={StaticResource Locator}}"
Thanks for the help.
I'm having some trouble setting the data context property of my ContentTemplate within my RadTabControl (a tab control by Telerik). Here is my XAML:
<telerik:RadTabControl Grid.Row="1" TabOrientation="Horizontal" ItemsSource="{Binding Counterparties}">
<telerik:RadTabControl.ContentTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!--<telerik:RadGridView Grid.Row="0" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.ConsolidatedPositions}" Name="ExposureView" VerticalAlignment="Stretch" AutoGenerateColumns="False" CanUserDeleteRows="False" CanUserInsertRows="False" IsTabStop="False" RowHeight="18" SelectionMode="Extended" SelectionUnit="Mixed" IsReadOnly="True" ShowGroupPanel="False" ColumnWidth="75" GroupRenderMode="Flat" CanUserSortGroups="False" CanUserSortColumns="True" FontSize="11" RowIndicatorVisibility="Collapsed">-->
<telerik:RadGridView Grid.Row="0" ItemsSource="{Binding Path=DataContext.ConsolidatedPositions}" Name="ExposureView" VerticalAlignment="Stretch" AutoGenerateColumns="False" CanUserDeleteRows="False" CanUserInsertRows="False" IsTabStop="False" RowHeight="18" SelectionMode="Extended" SelectionUnit="Mixed" IsReadOnly="True" ShowGroupPanel="False" ColumnWidth="75" GroupRenderMode="Flat" CanUserSortGroups="False" CanUserSortColumns="True" FontSize="11" RowIndicatorVisibility="Collapsed">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn Header="Cusip" DataMemberBinding="{Binding Path=Cusip, Mode=OneWay}"/>
<telerik:GridViewDataColumn Header="Description" DataMemberBinding="{Binding Path=Description, Mode=OneWay}" Width="150" />
<telerik:GridViewDataColumn Header="Par Net" DataMemberBinding="{Binding Path=ParNet, Mode=OneWay}" DataFormatString="N0" TextAlignment="Right" Width="100" CellStyleSelector="{StaticResource ParNetStyleSelector}"/>
<telerik:GridViewDataColumn Header="Dirty Price" DataMemberBinding="{Binding Path=Price, Mode=OneWay}" Width="80" DataFormatString="F3" TextAlignment="Right"/>
<telerik:GridViewDataColumn Header="Settled Position" DataMemberBinding="{Binding Path=SettledPosition, Mode=OneWay}" DataFormatString="N0" TextAlignment="Right" Width="105" CellStyleSelector="{StaticResource SettledPositionStyleSelector}"/>
<telerik:GridViewDataColumn Header="Repos/Reverse" DataMemberBinding="{Binding Path=Repos, Mode=OneWay}" DataFormatString="N0" TextAlignment="Right" Width="90" CellStyleSelector="{StaticResource ReposStyleSelector}" />
<telerik:GridViewDataColumn Header="Clean Market Net" DataMemberBinding="{Binding Path=CleanMarketNet, Mode=OneWay}" TextAlignment="Right" DataFormatString="N0" Width="120" CellStyleSelector="{StaticResource CleanMarketNetStyleSelector}" />
<telerik:GridViewDataColumn Header="Borrows/Lent" DataMemberBinding="{Binding Path=TotalBorrows, Mode=OneWay}" TextAlignment="Right" DataFormatString="N0" Width="100" CellStyleSelector="{StaticResource TotalBorrowStyleSelector}"/>
<telerik:GridViewDataColumn Header="Pledge In/Out" DataMemberBinding="{Binding Path=TotalPledges, Mode=OneWay}" Width="100" TextAlignment="Right" DataFormatString="N0" CellStyleSelector="{StaticResource TotalPledgesStyleSelector}"/>
<telerik:GridViewDataColumn Header="T+1 Net Pos" DataMemberBinding="{Binding Path=FutureNet1, Mode=OneWay}" Width="90" TextAlignment="Right" DataFormatString="N0" CellStyleSelector="{StaticResource FutureNet1StyleSelector}"/>
<telerik:GridViewDataColumn Header="T+2 Net Pos" DataMemberBinding="{Binding Path=FutureNet2, Mode=OneWay}" Width="90" TextAlignment="Right" DataFormatString="N0" CellStyleSelector="{StaticResource FutureNet2StyleSelector}"/>
<telerik:GridViewDataColumn Header="T+3 Net Pos" DataMemberBinding="{Binding Path=FutureNet3, Mode=OneWay}" Width="90" TextAlignment="Right" DataFormatString="N0" CellStyleSelector="{StaticResource FutureNet3StyleSelector}"/>
</telerik:RadGridView.Columns>
<telerik:RadGridView.InputBindings>
<KeyBinding Key="F2" Command="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ClearGridFiltersCommand}"></KeyBinding>
<!--<KeyBinding Key="F2" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.ClearGridFiltersCommand}" CommandParameter="{Binding ElementName=ExposureView}"></KeyBinding>-->
</telerik:RadGridView.InputBindings>
</telerik:RadGridView>
<StatusBar Grid.Row="1">
<StatusBar.ItemsPanel>
<ItemsPanelTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="200" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="50" />
</Grid.ColumnDefinitions>
</Grid>
</ItemsPanelTemplate>
</StatusBar.ItemsPanel>
<StatusBarItem Grid.Column="0">
<Label Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.Status}" Foreground="White"/>
</StatusBarItem>
<Separator Grid.Column="1" />
<StatusBarItem Grid.Column="2" >
<StackPanel Orientation="Horizontal">
<Label Content="Last Update:" Foreground="White" />
<Label Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.LastUpdate}" Foreground="White"/>
</StackPanel>
</StatusBarItem>
<Separator Grid.Column="3"/>
<StatusBarItem Grid.Column="4" HorizontalAlignment="Right">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<!--<Label Content="NET Pledged: " Foreground="White"></Label>-->
<!--<Label Content="{Binding NetPledged}" ContentStringFormat="{}{0:N0}" FontWeight="Bold" Foreground="{Binding Path=NetPledged, Converter={StaticResource RedNegativeLabelForegroundConverter}}"></Label>-->
<Label Content="Market Value Borrowed: " Foreground="White"/>
<Label Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.TotalParNet}" ContentStringFormat="{}{0:N0}" FontWeight="Bold" Foreground="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.TotalParNet, Converter={StaticResource RedNegativeLabelForegroundConverter}}"/>
<Label Content="Market Value Pledged: " Foreground="White"/>
<Label Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.TotalMarketValue}" ContentStringFormat="{}{0:N0}" FontWeight="Bold" Foreground="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.TotalMarketValue, Converter={StaticResource RedNegativeLabelForegroundConverter}}"/>
</StackPanel>
</StatusBarItem>
<Separator Grid.Column="5" />
<StatusBarItem Grid.Column="6" HorizontalAlignment="Right">
<Label Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.RecordCount}" Foreground="White"/>
</StatusBarItem>
</StatusBar>
</Grid>
</DataTemplate>
</telerik:RadTabControl.ContentTemplate>
</telerik:RadTabControl>
I'm using MVVM Light. The Counterparties' data context is my VM called MainViewModel. I want the ItemsSource of my GridView to be a different property of my ViewModel, called ConsolidatedPositions. So I want the RadGridView's DataContext to be the VM, **NOT** the collection of Counterparties, which it is currently doing.
I've found a temporary solution, but it is SLOW:
<!--<telerik:RadGridView Grid.Row="0" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}
My Windows DataContext:
DataContext="{Binding Main, Source={StaticResource Locator}}"
Thanks for the help.