积极答复者
请问 windowsphone7中 动态生成的控件 怎么给他加style?

问题
答案
-
看下你的Resource是不是放在StackPanel下,像这样
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"> <StackPanel.Resources> <Style x:Key="ButtonStyle1" TargetType="Button"> <!--...--> </Style> </StackPanel.Resources> </StackPanel>
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 海星C 2012年10月30日 1:52
全部回复
-
你好,
供参考:
Button b = new Button(); b.Height=72; b.Width=160; b.Content="Hello"; LayoutRoot.Children.Add(b); Style buttonstyle = LayoutRoot.Resources["ButtonStyle1"] as Style; b.Style = buttonstyle;
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
你好,
供参考:
Button b = new Button(); b.Height=72; b.Width=160; b.Content="Hello"; LayoutRoot.Children.Add(b); Style buttonstyle = LayoutRoot.Resources["ButtonStyle1"] as Style; b.Style = buttonstyle;
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
你好,谢谢你的帮助 ,
我这样写的
Button btn = new Button();
btn.Content = "click";
btn.Click += new RoutedEventHandler(btn_Click);
sta1.Children.Add(btn);Style buttonstyle = sta1.Resources["btnS"] as Style;
btn.Style = buttonstyle;//sta1是一个stackPanel , buttonstyle得到的是null..
-
看下你的Resource是不是放在StackPanel下,像这样
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"> <StackPanel.Resources> <Style x:Key="ButtonStyle1" TargetType="Button"> <!--...--> </Style> </StackPanel.Resources> </StackPanel>
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 海星C 2012年10月30日 1:52
-
看下你的Resource是不是放在StackPanel下,像这样
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"> <StackPanel.Resources> <Style x:Key="ButtonStyle1" TargetType="Button"> <!--...--> </Style> </StackPanel.Resources> </StackPanel>
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
非常感谢