TextBox字体系列绑定
本文关键字:绑定 系列 字体 TextBox | 更新日期: 2023-09-27 17:57:42
private System.Windows.Media.FontFamily fontfamily;
public System.Windows.Media.FontFamily FontFamily
{
get
{
return this.fontfamily;
}
set
{
this.fontfamily = value;
this.PropertyChanged(this, new PropertyChangedEventArgs("FontFamily"));
}
}
<ComboBox Height="20" SelectedValue="{Binding TopPanelViewModel.FontFamily,UpdateSourceTrigger=PropertyChanged}"
ItemsSource="{Binding Source={x:Static Fonts.SystemFontFamilies}}" Name="Type_Font" Width="120" Margin="20,0,10,0">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock FontFamily="{Binding .}" Text="{Binding Source}" FontSize="15"/>
</DataTemplate>
</ComboBox.ItemTemplate>
<ComboBox.ToolTip>
<TextBlock Text="{Binding LangiageViewModel.CurrentToolTips[25]}"></TextBlock>
</ComboBox.ToolTip>
</ComboBox>
<TextBox Style="{StaticResource HardBox}" Background="Transparent" TextWrapping="Wrap" x:Name="TextBoxInsertText"
FontFamily="{Binding TopPanelViewModel.FontFamily,UpdateSourceTrigger=PropertyChanged}"
AcceptsReturn="True" AcceptsTab="True" ScrollViewer.VerticalScrollBarVisibility="Disabled"
KeyUp="TextBoxInsertText_KeyDown" AllowDrop="True" IsUndoEnabled="True"
Visibility="{Binding VisibilityPropertiesViewModel.Instance.InsertTextVisibility,Converter={StaticResource BooleanToVisibilityConverter}}">
</TextBox>'
当组合框所选项目发生更改时,文本框族不会发生更改。该属性工作正常,但文本框fontfamily不正常。组合框和文本框位于不同的用户控件中。
更改TextBox
中的FontFamily
绑定
<TextBox Style="{StaticResource HardBox}" Background="Transparent"
TextWrapping="Wrap" x:Name="TextBoxInsertText"
FontFamily="{Binding ElementName="FontFamilyComboBox",Path=SelectedItem}"
AcceptsReturn="True" AcceptsTab="True" ScrollViewer.VerticalScrollBarVisibility="Disabled"
KeyUp="TextBoxInsertText_KeyDown" AllowDrop="True" IsUndoEnabled="True"
Visibility="{Binding VisibilityPropertiesViewModel.Instance.InsertTextVisibility,Converter={StaticResource BooleanToVisibilityConverter}}">
并在ComboBox
中添加Name
值
<ComboBox Height="20" x:Name="FontFamilyComboBox" SelectedValue="{Binding TopPanelViewModel.FontFamily,UpdateSourceTrigger=PropertyChanged}"
ItemsSource="{Binding Source={x:Static Fonts.SystemFontFamilies}}" Name="Type_Font" Width="120" Margin="20,0,10,0">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock FontFamily="{Binding .}" Text="{Binding Source}" FontSize="15"/>
</DataTemplate>
</ComboBox.ItemTemplate>
<ComboBox.ToolTip>
<TextBlock Text="{Binding LangiageViewModel.CurrentToolTips[25]}"></TextBlock>
</ComboBox.ToolTip>
</ComboBox>