积极答复者
如何在控件Style或ControlTemplate里面设置窗口的属性?

问题
答案
-
就是你这个style要是Window的Style,然后是:
<Style x:Key="SuperT" TargetType="{x:Type lib:SuperTextBox}">
<Setter Property="Window.Tag" Value“(Validation.HasError)"></Setter>注意 属性是Window。Tag,
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已建议为答案 Helper.WPF 2011年4月26日 6:00
- 已标记为答案 Sheldon _XiaoModerator 2011年5月3日 6:23
-
我只能写控件Style不能写Window.Style,只能在控件Style或ControlTemplate里面设置,所以才觉得困难的,如果不是因为Valiadton.HasError是只读属性,我就可以用OneWayToSource将值绑定到Window.Tag里面了,唉
- 已建议为答案 Helper.WPF 2011年4月26日 6:00
- 已标记为答案 Sheldon _XiaoModerator 2011年5月3日 6:23
-
呵呵 恐怕在Style里面去完成你这样的事情是不可以的了, 你只能去想想其他办法了。
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Sheldon _XiaoModerator 2011年5月3日 6:23
全部回复
-
可以,比如这样:
Tag = {Binding ElementName=_SELF, Path=(Validation.HasError)}
如果需要你也可以自己加个Convert。
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
<Style x:Key="SuperT" TargetType="{x:Type lib:SuperTextBox}">
<Setter Property="Tag" Value="{Binding ElementName=_SELF, Path=(Validation.HasError)}"></Setter>
呵呵,请说的全一点好吗,是这样写的吗,我这个是一个控件的样式,想将Valiadation.HasError绑定到调用这个控件的页面的Tag里面,让页面Tag保存这个Valiadation.HasError,<Style x:Key="SuperT" TargetType="{x:Type lib:SuperTextBox}">
<Setter Property="Tag" Value="{Binding ElementName=_SELF, Path=(Validation.HasError)}"></Setter>如果这样写的话不是绑定给了控件本身的Tag吗?
-
。。。
你现在要设置Window的tag属性,你就要在Window的style里面设置Tag属性啊。
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
就是你这个style要是Window的Style,然后是:
<Style x:Key="SuperT" TargetType="{x:Type lib:SuperTextBox}">
<Setter Property="Window.Tag" Value“(Validation.HasError)"></Setter>注意 属性是Window。Tag,
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已建议为答案 Helper.WPF 2011年4月26日 6:00
- 已标记为答案 Sheldon _XiaoModerator 2011年5月3日 6:23
-
我只能写控件Style不能写Window.Style,只能在控件Style或ControlTemplate里面设置,所以才觉得困难的,如果不是因为Valiadton.HasError是只读属性,我就可以用OneWayToSource将值绑定到Window.Tag里面了,唉
- 已建议为答案 Helper.WPF 2011年4月26日 6:00
- 已标记为答案 Sheldon _XiaoModerator 2011年5月3日 6:23
-
--> 如果不是因为Valiadton.HasError是只读属性,我就可以用OneWayToSource将值绑定到Window.Tag里面了
完全不懂! 什么意思? 什么叫绑定到Window.Tag里面?
你分享一下这个代码我看看,我觉得你仿佛理解有问题。
你现在假如他不是只读属性,你show一下你的实现方式我看看。
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
<Style x:Key="SuperT" TargetType="{x:Type lib:SuperTextBox}">
<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self},Path=(Validation.Errors)[0].ErrorContent}"></Setter>
<Setter Property="TempError" Value="{Binding RelativeSource={RelativeSource Self},Path=(Validation.HasError), Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"></Setter>
<Setter Property="HasError" Value="{Binding RelativeSource={RelativeSource Self}, Path=TempError, UpdateSourceTrigger=PropertyChanged}"></Setter>这里:
<Setter Property="Validation.HasError">
<Setter.Value>
<Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type Window}}"
Path="Tag" Mode="OneWayToSource" UpdateSourceTrigger="PropertyChanged">
</Binding>
</Setter.Value>
</Setter></Style>
-
我发现你这个TempError属性不是已经显示了HasError的值了么?
如果你希望Validation。HasError不是只读的,那你就用这个TempError属性不可以么?
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
不好意思,有点事回复的慢了,你是指:
<Setter Property="TempError">
<Setter.Value>
<Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type Window}}"
Path="Tag" Mode="OneWayToSource" UpdateSourceTrigger="PropertyChanged">
</Binding>吗?
可是这样的话TempError就是使用了两次Binding了,无效了,控件的一个属性绑定两次,他会都有用吗,我的TempError是要从Validation.HasError那里绑定来的哇 -
呵呵 恐怕在Style里面去完成你这样的事情是不可以的了, 你只能去想想其他办法了。
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Sheldon _XiaoModerator 2011年5月3日 6:23