积极答复者
为什么Silverlight背景颜色会自动改变?

问题
-
Why the background is changed after Controls generated?
Hi,
My Silverlight application has some elements for creating a new user. These elements use Style="{StaticResource ElementStyle}" settings. Also, there is a StackPanel which contains RadioButtons(Generate RadioButtons automatically by loop from a IList object, add these RadioButtons by method method StackPanel.Children.Add()). The data binding funcation will be implemented in the event of Layout_Loaded, the event invoke functions from a WCF services to provide IList object.
But I find that the background of Silverlight UI(Contained in a ASP.NET page.) will be changed while mouse is over, or clicking. Especially, the background of whole grid layout will be changed after generating RadioButtons.
Any idea for solving this problem?
Thanks
Jinhui
这个帖子本来发在英文版块的,但是现在没人回答.就重发在这里了.
在Silverlight 2.0的页面里,加了一些控件,整个布局就是一个用户注册.我发现SL的控件在整个页面加载完之后,后者鼠标点了让某个控件获得焦点,背景颜色就要变化,而且鼠标移走该控件失去焦点,背景颜色依然存在;更严重的是, 等整个页面加载完成,整个背景都变了,而我并没有设置背景.考虑到可能是ContentTemplate的问题....各位遇到过吗?
关于楼上的代码,我测试给出附图如下
附图一:页面完成后只有背景色(我的代码居然没有设置背景色都会自动加背景色,看来得人为设置一个?)- 已编辑 魑魅魍魉 4 Ghosts 2009年7月29日 6:29
- 已更改类型 Allen Chen - MSFTModerator 2009年8月5日 1:29 由于长时间未见楼主回复,暂时改为一般讨论
- 已更改类型 Allen Chen - MSFTModerator 2009年8月25日 1:36
答案
-
在aspx页面中去掉下面这个参数:
<param name="enableRedrawRegions" value="true" />
我的就是这样生效的
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="ClientBin/SilverlightApp.xap"/>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="3.0.40624.0" />
<param name="autoUpgrade" value="true" />
<param name="enableRedrawRegions" value="true" />
<param name="initParams" value="key1=value1,key2=value2" />
<a href="ClientBin/Silverlight.exe" style="text-decoration:none">
<img src="ClientBin/InstallSilverlight.png" alt="Get Microsoft Silverlight" style="border-style:none"/>
</a>
</object>- 已标记为答案 Allen Chen - MSFTModerator 2009年8月25日 1:36
全部回复
-
I`m try! But I did not find .
Is to understand where I wrong? You can Call me. QQ:283440946<UserControl x:Class="SilverlightApplication19.Page" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="400" Height="300" Loaded="UserControl_Loaded"> <UserControl.Resources> <Style x:Name="style1" TargetType="Grid"> <Setter Property="Background" Value="#FF00FF00"/> </Style> </UserControl.Resources> <Grid x:Name="LayoutRoot" Style="{StaticResource style1}" > <StackPanel x:Name="tt" > </StackPanel> </Grid> </UserControl>
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; namespace SilverlightApplication19 { public partial class Page : UserControl { public Page() { InitializeComponent(); } private void UserControl_Loaded(object sender, RoutedEventArgs e) { for (int i = 0; i < 10; i++) { RadioButton rad = new RadioButton(); rad.Content = ""+i; this.tt.Children.Add(rad); } } } }
努力!写一个js解析器,一个svg插件,一个绘图程序,做好自己,呵呵~! -
for (int i = 0; i < 10; i++)
{
RadioButton rad = new RadioButton();
rad.Content = ""+i;
this.tt.Children.Add(rad);
}Button btn = new Button ( );
btn.Content = "Button1";this.tt.Children.Add ( btn );
这个帖子本来发在英文版块的,但是现在没人回答.就重发在这里了.
在Silverlight 2.0的页面里,加了一些控件,整个布局就是一个用户注册.我发现SL的控件在整个页面加载完之后,后者鼠标点了让某个控件获得焦点,背景颜色就要变化,而且鼠标移走该控件失去焦点,背景颜色依然存在;更严重的是, 等整个页面加载完成,整个背景都变了,而我并没有设置背景.考虑到可能是ContentTemplate的问题....各位遇到过吗?
关于楼上的代码,我测试给出附图如下
附图一:页面完成后只有背景色(我的代码居然没有设置背景色都会自动加背景色,看来得人为设置一个?)
附图二:鼠标点击Button1后, 再点击某个RadioButton, Button1依然存在背景色.
谢谢.
民主是人类社会的普遍价值观.(Democratic is a common value of the human society) -
我的也是SL 2.0.我按你的说法后台代码改成:
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
}private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
for (int i = 0; i < 10; i++)
{
RadioButton rad = new RadioButton();
rad.Content = ""+i;
this.tt.Children.Add(rad);
}
Button btn = new Button();
btn.Content = "Button1";
btn.Background = new SolidColorBrush(Colors.Yellow);
this.tt.Children.Add(btn);
}}
但是没有什么差别! 背景是什么还是什么颜色
努力!写一个js解析器,一个svg插件,一个绘图程序,做好自己,呵呵~! -
<Style x:Key="GridStyle"
TargetType="Grid">
<Setter Property="HorizontalAlignment"
Value="Stretch" />
<Setter Property="ShowGridLines"
Value="True" />
<Setter Property="Background"
Value="White" />
<Grid x:Name="LayoutRoot"
Style="{StaticResource GridStyle}"
Loaded="LayoutRoot_Loaded">
</Grid>
就这样的代码,没有用第三方控件.
虽然设置了Background = "White", 等执行完LayoutRoot_Loaded还是会变绿,我怀疑这个是一个sl或者ie 8.0的bug
民主是人类社会的普遍价值观.(Democratic is a common value of the human society) -
你好,
请提供一下可以重现问题的项目.
请上传到http://skydrive.live.com/然后在这里给出下载连接.
Please remember to mark the replies as answers if they help and unmark them if they provide no help. Need a sample of a technique of Microsoft? Just check out CodeFx first! http://cfx.codeplex.com/ -
在aspx页面中去掉下面这个参数:
<param name="enableRedrawRegions" value="true" />
我的就是这样生效的
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="ClientBin/SilverlightApp.xap"/>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="3.0.40624.0" />
<param name="autoUpgrade" value="true" />
<param name="enableRedrawRegions" value="true" />
<param name="initParams" value="key1=value1,key2=value2" />
<a href="ClientBin/Silverlight.exe" style="text-decoration:none">
<img src="ClientBin/InstallSilverlight.png" alt="Get Microsoft Silverlight" style="border-style:none"/>
</a>
</object>- 已标记为答案 Allen Chen - MSFTModerator 2009年8月25日 1:36