我是wpf的新手,我想在ComboBox中使用DataGrid而不是默认的ItemPresenter并搜索并找到一个示例,但是当我在组合框中选择嵌套数据网格中的项目时,注意到了
这可能是测试代码
<Style x:Key="DataGridComboBoxStyle" TargetType="{x:Type ComboBox}">
<Setter Property="Foreground" Value="DimGray" />
<Setter Property="BorderBrush" Value="LightGray" />
<Setter Property="Background" Value="White" />
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
<Setter Property="FontSize" Value="12" />
<Setter Property="FontFamily" Value="Tahoma, Verdana" />
<Setter Property="Height" Value="25" />
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="MaxDropDownHeight" Value="250" />
<Setter Property="StaysOpenOnEdit" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBox">
<Grid>
<ToggleButton BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" Grid.ColumnSpan="2" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
<ToggleButton.Style>
<Style TargetType="{x:Type ToggleButton}">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="Focusable" Value="False"/>
<Setter Property="ClickMode" Value="Press"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Themes:ButtonChrome x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}" SnapsToDevicePixels="True">
<Grid HorizontalAlignment="Right" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}">
<Path x:Name="Arrow" Data="M0,0L3.5,4 7,0z" Fill="Black" HorizontalAlignment="Center" Margin="3,1,0,0" VerticalAlignment="Center"/>
</Grid>
</Themes:ButtonChrome>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="RenderPressed" TargetName="Chrome" Value="True"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Fill" TargetName="Arrow" Value="#FFAFAFAF"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ToggleButton.Style>
</ToggleButton>
<ContentPresenter Name="ContentSite"
IsHitTestVisible="False"
Content="{Binding ElementName=ItemsPresenter, Path=SelectedItem}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
Margin="10,3,30,3"
VerticalAlignment="Center"
HorizontalAlignment="Center" />
<TextBox x:Name="PART_EditableTextBox"
Style="{x:Null}"
SelectionBrush="Transparent"
Template="{DynamicResource ComboBoxTextBox}"
Text="{Binding ElementName=ItemsPresenter, Path=SelectedItem}"
Foreground="{TemplateBinding Foreground}"
FontFamily="{TemplateBinding FontFamily}"
FontSize="{TemplateBinding FontSize}"
FontWeight="{TemplateBinding FontWeight}"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Left"
VerticalAlignment="Stretch"
VerticalContentAlignment="Center"
Background="Transparent"
Margin="3,3,23,3"
Focusable="True"
Visibility="Hidden"
IsReadOnly="{TemplateBinding IsReadOnly}"/>
<Popup Name="Popup"
Placement="Bottom"
IsOpen="{TemplateBinding IsDropDownOpen}"
AllowsTransparency="True"
Focusable="False"
PopupAnimation="Slide">
<Grid Name="DropDown"
SnapsToDevicePixels="True"
MinWidth="{TemplateBinding ActualWidth}"
MaxHeight="{TemplateBinding MaxDropDownHeight}">
<Border x:Name="DropDownBorder"
Background="White"
BorderThickness="1"
BorderBrush="LightGray"/>
<ScrollViewer Margin="1,2" SnapsToDevicePixels="True" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Disabled">
<StackPanel Orientation="Vertical" >
<telerik:RadGridView
Name="ItemPresenter" ScrollViewer.CanContentScroll="True"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ItemsSource="{TemplateBinding ItemsSource}"
BorderBrush="Transparent"
ShowGroupPanel="False"
RowHeight="20"
KeyboardNavigation.DirectionalNavigation="Contained"
AutoGenerateColumns ="False"
CanUserDeleteRows="False">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn DataMemberBinding="{Binding FullName, Mode=OneWay}" Header="نام خانوادگی" IsReadOnly="True" Width="auto"/>
<telerik:GridViewDataColumn DataMemberBinding="{Binding FatherName, Mode=OneWay}" Header="نام پدر" IsReadOnly="True" Width="auto"/>
<telerik:GridViewDataColumn DataMemberBinding="{Binding Phone, Mode=OneWay}" Header="شماره تلفن" IsReadOnly="True" Width="auto"/>
<telerik:GridViewDataColumn DataMemberBinding="{Binding Mobile, Mode=OneWay}" Header="موبایل" IsReadOnly="True" Width="auto"/>
</telerik:RadGridView.Columns>
</telerik:RadGridView>
<Border BorderBrush="LightGray" BorderThickness="0, 1, 0, 0">
<DockPanel LastChildFill="True" Background="White" Margin="5">
<Button Style="{DynamicResource DataGridPagingButtonStyle}" DockPanel.Dock="Left" >
<Button.Content>
<UniformGrid Margin="1">
<Path Height="20" Width="20" Stroke="DarkGray" Stretch="Uniform" StrokeThickness="1" Data="M 4,1 L 1,4 L 4,7" />
</UniformGrid>
</Button.Content>
</Button>
<Button Style="{DynamicResource DataGridPagingButtonStyle}" DockPanel.Dock="Right">
<Button.Content>
<UniformGrid Margin="1">
<Path Height="20" Width="20" Stroke="DarkGray" Stretch="Uniform" StrokeThickness="1" Data="M1,1 L4,4 1,7" />
</UniformGrid>
</Button.Content>
</Button>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" DockPanel.Dock="Left">
<TextBlock FontFamily="Tahoma, Verdana" FontSize="11" Foreground="DimGray" VerticalAlignment="Center" Padding="0, 0, 5, 2" Text="Page" />
<TextBox BorderBrush="LightGray" FontFamily="Tahoma, Verdana" FontSize="11" Foreground="DimGray" Height="20" Width="20" HorizontalContentAlignment="Center" Text="1" />
<TextBlock FontFamily="Tahoma, Verdana" FontSize="11" Foreground="DimGray" VerticalAlignment="Center" Padding="5, 0, 5, 2" Text="to" />
<TextBlock FontFamily="Tahoma, Verdana" FontSize="11" Foreground="DimGray" VerticalAlignment="Center" Padding="0, 0, 0, 2" Text="(bind pages)" />
</StackPanel>
</DockPanel>
</Border>
</StackPanel>
</ScrollViewer>
</Grid>
</Popup>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>