Difference between revisions of "WPF DataGrid with dynamic cols"
(→X) |
(→X) |
||
Line 4: | Line 4: | ||
</source> | </source> | ||
+ | |||
+ | === MainWindow.xaml === | ||
+ | <source lang="xml"> | ||
+ | <Window x:Class="ControlsTestProject.MainWindow" | ||
+ | xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
+ | xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
+ | xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
+ | xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
+ | xmlns:local="clr-namespace:ControlsTestProject" | ||
+ | mc:Ignorable="d" | ||
+ | Title="MainWindow" Height="350" Width="525"> | ||
+ | <Window.Resources> | ||
+ | <local:TableVm x:Key="ViewModel"/> | ||
+ | </Window.Resources> | ||
+ | |||
+ | <StackPanel DataContext="{Binding Source={StaticResource ViewModel}}"> | ||
+ | |||
+ | <local:MyTable /> | ||
+ | |||
+ | </StackPanel> | ||
+ | </Window> | ||
+ | </source> | ||
+ | |||
+ | |||
+ | === MyTable.xaml === | ||
+ | <source lang="xml"> | ||
+ | <UserControl x:Class="ControlsTestProject.MyTable" | ||
+ | xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
+ | xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
+ | xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
+ | xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
+ | xmlns:local="clr-namespace:ControlsTestProject" | ||
+ | mc:Ignorable="d" | ||
+ | d:DesignHeight="300" d:DesignWidth="300"> | ||
+ | |||
+ | |||
+ | |||
+ | <Grid> | ||
+ | |||
+ | <DataGrid x:Name="MyDataGrid" | ||
+ | ItemsSource="{Binding Path=Rows}" | ||
+ | AutoGenerateColumns="False" | ||
+ | CanUserAddRows="False"> | ||
+ | |||
+ | </DataGrid> | ||
+ | </Grid> | ||
+ | </UserControl> | ||
+ | </source> | ||
+ | |||
+ | |||
+ | === X === | ||
+ | <source lang="xml"> | ||
+ | |||
+ | </source> | ||
+ | |||
+ | |||
+ | === X === | ||
+ | <source lang="xml"> | ||
+ | |||
+ | </source> | ||
=== X === | === X === |
Revision as of 10:05, 18 June 2016
Contents
X
MainWindow.xaml
<Window x:Class="ControlsTestProject.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ControlsTestProject"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<local:TableVm x:Key="ViewModel"/>
</Window.Resources>
<StackPanel DataContext="{Binding Source={StaticResource ViewModel}}">
<local:MyTable />
</StackPanel>
</Window>
MyTable.xaml
<UserControl x:Class="ControlsTestProject.MyTable"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ControlsTestProject"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<DataGrid x:Name="MyDataGrid"
ItemsSource="{Binding Path=Rows}"
AutoGenerateColumns="False"
CanUserAddRows="False">
</DataGrid>
</Grid>
</UserControl>
X