私はWindowsフォームを使用したVB.NETおよびC#のプロのWindowsアプリケーション開発者であり、WPF開発に踏み込むことに非常に興奮しています。ここで私が検索して解決できなかった私の最初の問題:
ボタンの外観を完全に変更するために、次のテンプレートを作成しました。
<ControlTemplate TargetType="{x:Type Button}" x:Key="ImageButtonTemplate">
<Grid>
<Image Name="img" Source="/PSPlayer;component/Images/Buttons/ButtonNormal_normal.png"/>
<ContentPresenter Stylus.IsTapFeedbackEnabled="False" Stylus.IsTouchFeedbackEnabled="False" Stylus.IsPressAndHoldEnabled="False" Stylus.IsFlicksEnabled="False" Width="98" Height="61"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="img" Property="Source" Value="/PSPlayer;component/Images/Buttons/ButtonNormal_MouseOver.png"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="img" Property="Source" Value="/PSPlayer;component/Images/Buttons/ButtonNormal_MouseDown.png"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
そしてここにボタンの定義:
<Button Content="SomeText" Height="61" Margin="0,0,0,7" Name="button7" Width="98" Click="button7_Click" Template="{StaticResource ImageButtonTemplate}"/>
問題は、ボタンの左上に「SomeText」というテキストが表示され、その場所を変更できないことです。ボタンのプロパティHorizontalContentAlignmentとVerticalContentAlignmentは効果を示しません(なぜだろうと思います)。
さらに、背景画像にx = 60まで左側に配置される記号が含まれている場合、x = 70のように、テキストを特定の場所に配置したいと思います。
ボタンの内側にラベルを埋め込んで配置できるウォークアラウンドを作成しましたが、よりクリーンな解決策があるはずだと思います。
私が自分自身を明確にしたことを願っています。ちなみに、WPFルールズ-このサイトと同様に、私がここからの投稿で解決した問題のほとんど(グーグルから来る):)
前もって感謝します、
ジュリアン