0
我要打電話按鈕樣式靜態資源在後臺代碼採用C#如何將Button.Style設置爲x:來自WPF後面代碼的靜態資源?
這是我的按鈕在XAML:
<Button Height="48" HorizontalAlignment="Left" Margin="229,0,0,0" Name="btnlogin"
VerticalAlignment="Top" Width="90" Grid.Row="6" BorderThickness="0"
MouseEnter="btnlogin_MouseEnter" MouseLeave="btnlogin_MouseLeave"
BorderBrush="Transparent"
Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}">
<Button.Background>
<ImageBrush ImageSource="/BaccaratDealerInterfaceWPF;component/Images/Login_Button_Normal.png" />
</Button.Background>
</Button>
我需要在後面的C#代碼來設置這個Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
到btnlogin.Style
財產。
我已經試過
Style style = this.FindResource("{x:Static ToolBar.ButtonStyleKey}") as Style;
btnlogin.Style = style;
請說明您的ToolBar.ButtonStyleKey是如何聲明的,但是如果您擁有x:Key =「MyStyle」的資源,那麼要使用它,您應該這樣做:this.FindResource(「MyStyle」) – MistyK