3

多言語をサポートするスタンドアロンの WPF アプリを作成しています。必要に応じて文字列を保存およびアクセスする方法について、いくつかの優れたリソース (主に SO 上) を見つけました。この部分は非常に簡単で実行可能ですが、画面レイアウトの問題を処理する方法がわかりません。

ボタンなどのアプリをスキンアップするために、いくつかのカスタム画像を使用しています。たとえば、テキストが含まれるボタンは次のとおりです。

   <Button
        Canvas.Left="33"
        Canvas.Top="484"
        Style="{StaticResource SmallButtonBase}">
        <TextBlock                 
            FontSize="20" 
            FontWeight="Bold"        
            TextAlignment="Center" FontFamily="Helvetica">                                
            Enter
        </TextBlock>
    </Button>

代替テキスト

別の言語のテキストを含む同じボタンを次に示します。

   <Button
        Canvas.Left="33"
        Canvas.Top="484"
        Style="{StaticResource SmallButtonBase}">
        <TextBlock                 
            FontSize="20" 
            FontWeight="Bold"        
            TextAlignment="Center" FontFamily="Helvetica">                                
            Enterenschtein
        </TextBlock>
    </Button>

代替テキスト

私の質問は次のとおりです。この「オーバーフロー」の状況を防ぐための良い方法は何ですか。サポートしている言語ごとに UI を微調整する必要がないように、必要なフォントのサイズ変更やインデントを XAML に自動的に処理してもらいたいと考えています。

どんな洞察も大歓迎です!

ps SmallButtonBase の XAML は次のとおりです。基本的に、ボタンにフォーカスがあるとき、またはボタンが押されたときに何が起こるかを定義します。ケースごとに異なる画像が使用されます。

<Style x:Key="SmallButtonBase" TargetType="Button">
    <Setter Property="FocusVisualStyle" Value="{x:Null}" />
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Button">
                <Grid x:Name="Container">
                    <Image x:Name="Img" Source="/Resources/Elements/Buttons/10.png" Margin="6" />
                    <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsKeyboardFocused" Value="True">
                        <Setter TargetName="Img" Property="Source" Value="/Resources/Elements/Buttons/11.png" />
                        <Setter TargetName="Img" Property="Margin" Value="0" />
                    </Trigger>
                    <MultiTrigger>
                        <MultiTrigger.Conditions>
                            <Condition Property="IsKeyboardFocused" Value="True" />
                            <Condition Property="IsPressed" Value="True" />
                        </MultiTrigger.Conditions>
                        <Setter TargetName="Img" Property="Source" Value="/Resources/Elements/Buttons/12.png" />
                    </MultiTrigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
4

1 に答える 1

2

ボタンの画像と一致する固定の幅と高さで、contentpresenter の周りにビューボックスを配置してみてください。

このような

<Viewbox Width="85" Height="85">
    <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Viewbox>

その場合、WPF がその場所に収まるようにフォントを拡大縮小できると思います。

于 2010-04-23T17:30:11.513 に答える