Visual Studio / WPF > Resources / Style > x:Keyを指定しない Implicit keyの例
4942 ワード
動作環境
Windows 7 Pro (32bit)
Microsoft Visual Studio 2017 Community
Styles, DataTemplates, and Implicit Keys
...
The implicit key from the standpoint of requesting it is the Type of the control itself. The implicit key from the standpoint of defining the resource is the TargetType of the style.
Styleに関して、x:Keyを指定せずにTargetTypeで定義しておけばStyleを変更できるとのこと。
MainWindow.xaml
<Window x:Class="_170615_t1450_ImplicitKey.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:_170615_t1450_ImplicitKey"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<Style TargetType="Button">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush>
<GradientStop Offset="0.0" Color="AliceBlue"/>
<GradientStop Offset="1.0" Color="Salmon"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="FontSize" Value="18"/>
</Style>
</Window.Resources>
<Grid>
<StackPanel>
<Button Width="100" Height="28" Content="Button1"/>
<Button Width="100" Height="28" Content="Button2"/>
<Button Width="100" Height="28" Content="Button3"/>
</StackPanel>
</Grid>
</Window>
関連リンク
スタイルの暗黙的な適用
Author And Source
この問題について(Visual Studio / WPF > Resources / Style > x:Keyを指定しない Implicit keyの例), 我々は、より多くの情報をここで見つけました https://qiita.com/7of9/items/f2e39938d00a8f0aca1a著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .