ComboBox模版样式绑定问题~
Item样式
<Style x:Key="{x:Type ComboBoxItem}" TargetType="{x:Type ComboBoxItem}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Height" Value="28" />
<Setter Property="Width" Value="{Binding Width}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBoxItem">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80" />
<ColumnDefinition Width="140*" />
</Grid.ColumnDefinitions>
<Border x:Name="itembg" Grid.ColumnSpan="2" Width="{TemplateBinding Width}" Height="30" Background="White"
BorderThickness="2,1,2,1" BorderBrush="#bcbcbc" VerticalAlignment="Bottom" ></Border>
<Border Width="1" Height="30" Background="#bcbcbc" CornerRadius="15" Margin="0,1,0,1"
BorderThickness="2" BorderBrush="#bcbcbc" VerticalAlignment="Bottom" HorizontalAlignment="Right"></Border>
<TextBlock Text="{Binding ID}" HorizontalAlignment="Right" Margin="0,0,3,0" />
<TextBlock Text="{Binding FName}" Grid.Column="1" HorizontalAlignment="Left" Margin="3,0,0,0" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="itembg" Property="Background" Value="#c1c1c1"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="DefaultComboBoxStyle" TargetType="ComboBox">
<Setter Property="Background" Value="White"/>
<Setter Property="FontSize" Value="16"/>
<Setter Property="BorderBrush" Value="#bcbcbc" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBox">
<Grid x:Name="MainGrid" >
<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 Background="Transparent" BorderThickness="0,0,0,2" BorderBrush="#bcbcbc" />
<ScrollViewer SnapsToDevicePixels="True">
<StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" />
</ScrollViewer>
</Grid>
</Popup>
<ToggleButton Style="{StaticResource ComboBoxReadonlyToggleButton}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" />
<ContentPresenter Margin="10,0,0,0"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
IsHitTestVisible="false"
Content="{TemplateBinding SelectionBoxItem}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<ComboBox Name="dropBookID" Width="220" Grid.Row="2" SelectedValue="{Binding BookID, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource DefaultComboBoxStyle}" HorizontalAlignment="Left" />
IList<t_book> book = (List<t_book>)DTList.DateTabletoList<t_book>(new t_book().GetList("").Tables[0]);
dropBookID.ItemsSource = book;
this.dropBookID.DisplayMemberPath = "FName";
this.dropBookID.SelectedValuePath = "ID";
this.dropBookID.SelectedIndex = 0;