アプリケーションのカスタム ボタンをブレンドで作成し、そのリソースを xaml コードで使用しました。しかし、私は自分のクラス xyztextbutton でそれを使用したいと考えています。しかし、そうすることができません。
[ button.Style = (Style)Application.Current.Resources["ButtonStyle1"];] が正しく動作しない
そして、後でレイアウトルートに追加していますが、まだ機能していません。
phone:PhoneApplicationPage
x:Class="xyz.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True" xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit">
<phone:PhoneApplicationPage.Resources>
<Style x:Key="ButtonStyle1" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Pressed">
<Storyboard>
<ColorAnimation Duration="0" To="#FF216391" Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" Storyboard.TargetName="path" d:IsOptimized="True"/>
<ColorAnimation Duration="0" To="#FF3E8EBB" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="path" d:IsOptimized="True"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Normal"/>
<VisualState x:Name="Disabled"/>
<VisualState x:Name="MouseOver"/>
</VisualStateGroup>
<VisualStateGroup x:Name="FocusStates">
<VisualState x:Name="Focused"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Path x:Name="path" Data="M22.729,0 L22.73,0 L107.729,0 L107.729,38 L22.76,38 L22.76,38.031 L-0.483128,19.5199 L22.729,0.000793 z" Stretch="Fill" UseLayoutRounding="False" Stroke="#FFD0E21D" StrokeThickness="2" Fill="#FF5FB4E4" Margin="-0.483,0,0,0"/>
<ContentPresenter HorizontalAlignment="Center" Margin="24,1,4,9" Width="80" Height="30" OpacityMask="Black" VerticalAlignment="Top"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</phone:PhoneApplicationPage.Resources>
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="White" Height="800">
<Grid.RowDefinitions>
<!--<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>-->
</Grid.RowDefinitions>
</Grid>
public class xyzTextButton
{
private int ScreenWidth = Convert.ToInt32(Application.Current.Host.Content.ActualWidth);
private int ScreenHeight = Convert.ToInt32(Application.Current.Host.Content.ActualHeight);
Grid uiGrid = null;
Image image = null;
TextBlock textblock = null;
Button button = null;
Dictionary<string, object> actions = null;
public void CreateTextButton(Dictionary<string, object> dict, Grid grid, string pagename)
{
uiGrid = new Grid();
image = new Image();
button = new Button();
button.Style = (Style)Application.Current.Resources["ButtonStyle1"];
textblock = new TextBlock();
Boolean autoresizesSubviews = Convert.ToBoolean(ObjectForKey("autoresizesSubviews", dict));
actions = (Dictionary<string, object>)ObjectForKey("actions", dict);
}
}