0

App.xaml で TextBox の FontFamily を定義した後、何も変わっていないのは少し奇妙です。コードは

<Style TargetType="TextBox">
        <Setter Property="FontFamily" Value="Fonts/WenQuanYiMicroHei.ttf#WenQuanYiMicroHei"/>
    </Style>

TargetType を "TextBlock" に変更すると、TextBlock はフォント ファミリを変更します。

さらに、次のような TextBock のスタイルも定義しました。

<Style x:Key="TextBoxStyle4FF" TargetType="TextBox">
        <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMediumLarge}"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Foreground" Value="White"/>
        <Setter Property="BorderBrush" Value="White"/>
        <Setter Property="SelectionBackground" Value="{StaticResource PhoneAccentBrush}"/>
        <Setter Property="SelectionForeground" Value="{StaticResource PhoneTextBoxSelectionForegroundBrush}"/>
        <Setter Property="BorderThickness" Value="2"/>
        <Setter Property="Padding" Value="0"/>
        <Setter Property="CaretBrush" Value="White"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="TextBox">
                    <Grid Background="Transparent">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="MouseOver"/>
                                <VisualState x:Name="Disabled">
                                </VisualState>
                                <VisualState x:Name="ReadOnly">
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="FocusStates">
                                <VisualState x:Name="Focused">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="EnabledBorder">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Transparent"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="EnabledBorder">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="White"/>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Unfocused"/>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Border x:Name="EnabledBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Margin="0">
                            <ContentControl x:Name="ContentElement" BorderThickness="0" HorizontalContentAlignment="Stretch" Margin="{StaticResource PhoneTextBoxInnerMargin}" Padding="0" VerticalContentAlignment="Stretch" FontFamily="{TemplateBinding FontFamily}"/>
                        </Border>
                        <Border x:Name="DisabledOrReadonlyBorder" BorderBrush="{StaticResource PhoneDisabledBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="Transparent" Margin="{StaticResource PhoneTouchTargetOverhang}" Visibility="Collapsed">
                            <TextBox x:Name="DisabledOrReadonlyContent" Background="Transparent" Foreground="{StaticResource PhoneDisabledBrush}" FontWeight="{TemplateBinding FontWeight}" FontStyle="{TemplateBinding FontStyle}" FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" IsReadOnly="True" SelectionForeground="{TemplateBinding SelectionForeground}" SelectionBackground="{TemplateBinding SelectionBackground}" TextAlignment="{TemplateBinding TextAlignment}" TextWrapping="{TemplateBinding TextWrapping}" Text="{TemplateBinding Text}" Template="{StaticResource PhoneDisabledTextBoxTemplate}"/>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

TextBox の Style 定義によるものでしょうか。

そこで、TextBox の FontFamily リソースを定義することにしましたが、FontFamily を定義する方法が見つかりませんでした。FontFamily はSystem.Windows.Media名前空間にあるようですが、この名前空間を追加して xmlns:media="clr-namespace:System.Windows.Media;assembly=System.Windows"も無駄です。

どんな返信でも大歓迎です。

4

2 に答える 2

1

このパターンに基づいて:

<FontFamily x:Key="CantarellFontFamily" >Fonts/Cantarell-Regular.ttf#Cantarell</FontFamily>

私はこれを作成しました:

<FontFamily x:Key="CantarellFontFamily" >Fonts/Cantarell-Regular.ttf#Cantarell</FontFamily>

私は Windows Phone 7.1 で次のように作業しました。

<TextBlock FontFamily="{StaticResource CantarellFontFamily}" />

http://msdn.microsoft.com/en-us/library/system.windows.media.fontfamily(v=vs.95).aspxでドキュメントを確認できます。

よろしく、ハーバー

于 2012-07-19T19:49:53.743 に答える
0

新しいスタイルは、既に定義されているスタイルに基づいている必要があります。

<Style TargetType="TextBox" x:Key="baseStyle>
    <Setter Property="FontFamily" 
            Value="Fonts/WenQuanYiMicroHei.ttf#WenQuanYiMicroHei"/>
</Style>

<Style x:Key="TextBoxStyle4FF" TargetType="TextBox" 
      BasedOn={StaticResource baseStyle}> <!-- based on defined style -->

ご覧のとおり、元のスタイルにキーを与える必要があります。

于 2012-04-19T15:52:34.903 に答える