当我尝试在窗体设计器中更改Windows窗体上的控件的默认图像时(无论在哪个控件上),我收到此错误:
错误消息:已添加具有相同键的项目
我试图删除并重新创建Resources.resx文件..我保证只有1个具有这些密钥的resx文件存在..(实际上这是我唯一的资源文件)但它仍然不起作用.
我有som字符串和一些图像.就这样.
任何的想法?
我想制作一个适用于不同类型T 的可重用WPF窗口.我有一个设计器和一个代码隐藏文件.
我可以这样做吗?
/* Code behind file */
public partial class MyWindows<T> : Window
{}
Run Code Online (Sandbox Code Playgroud) 假设我们有一个非常"XAML长" ControlTemplate
为我们的Control
.我们只想在模板中添加1个按钮.MSDN声称" 无法替换控件的部分可视树 ".我真的必须复制所有ControlTemplate并将我的Button添加到它吗?
或者:有没有可能如何为特定元素提供某种接口?例如TextBox,这样每个人都可以轻松地对其进行模板化,而无需重新整理整个ControlTemplate.
谢谢 !
我在默认模板中使用TextBox进行自定义控制.自定义控件具有以下2个依赖项属性(以及其他属性):
SelectedValue,NullText(当没有选择任何内容并提供值时,文本将显示在TextBox中)
我想在null为null 时将TextBox.Text设置为NullText值.SelectedValue
NullText
<TextBox.Text>
<MultiBinding Converter="{StaticResource myConverter}">
<Binding RelativeSource="TemplatedParent" Path="SelectedValue"/>
<Binding RelativeSource="TemplatedParent" Path="NullText"/>
</MultiBinding>
</TextBox.Text>
Run Code Online (Sandbox Code Playgroud)
我有一个IMultiValueConverter:
public class MyConverter : IMultiValueConverter
{}
Run Code Online (Sandbox Code Playgroud)
有了这个XAML定义,我得到'type没有公共TypeConverter类'Exception
你好吗?
首先,我不得不说我要谈谈System.ComponentModel.Component
.
您知道,我知道,.NET Component Model
提供能力(通过站点服务)来定义单独的Components
,因此它们可以以松散耦合的方式相互通信,并且每个都Component
可以轻松替换.
但我要说的是,我能以其他方式做到这一点:我的意思是,如果我在正确的设计SW Object Oriented Programming
的方式,我可以用的手段Abstract classes
,Interfaces
等实现上述所有的功能/互操作性.
那么为什么和何时我要依靠组件模型?
我有一个控件与此验证
<MyPicker.SelectedItem>
<Binding Path="Person.Value" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" NotifyOnValidationError="True">
<Binding.ValidationRules>
<rules:MyValidationRule ValidationType="notnull"/>
</Binding.ValidationRules>
</Binding>
</MyPicker.SelectedItem>
Run Code Online (Sandbox Code Playgroud)
这是验证类:
class MyValidationRule : ValidationRule
{
private string _validationType;
public string ValidationType
{
get { return _validationType; }
set { _validationType = value; }
}
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
ValidationResult trueResult = new ValidationResult(true, null);
switch (_validationType.ToLower())
{
case "notnull": return value == null ? new ValidationResult(false, "EMPTY FIELD") : trueResult;
default: return trueResult;
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题:更改属性后,将调用Validate()方法,该方法是正确的.
但是在创建MyControl时最初调用此方法?我需要在初始化后立即证明控件中是否存在空值(并显示验证错误)
我有一个WPF UserControl,其中有许多其他控件.TextBoxes就是其中之一.每个TextBox都有自己的验证:
<TextBox>
<TextBox.Text>
<Binding Path="MyPath" StringFormat="{}{0:N}" NotifyOnValidationError="True">
<Binding.ValidationRules>
<r:MyValidationRule ValidationType="decimal" />
</Binding.ValidationRules>
</Binding>
<TextBox.Text>
<TextBox>
Run Code Online (Sandbox Code Playgroud)
一个
现在假设用户在其中键入了一些无效字符.它们都会变成红色.
现在我想重置所有验证错误(由不正确的输入),并设定近期的正确值来自何处DataContext
.
我在构造函数中设置了DataContext,我不想更改它(DataContext = null对我没有帮助):
DataContext = _myDataContext = new MyDataContext(..);
Run Code Online (Sandbox Code Playgroud)
我已经找到的是这些课程:
Validation.ClearInvalid(..)
BindingExpression.UpdateTarget();
Run Code Online (Sandbox Code Playgroud)
我认为这些课程可以帮助我,但是他们需要Binding
一个具体的课程FrameworkElement
,我想为所有这些课程全球化.
我是否应该遍历Visual Tree(这实际上是我不喜欢的)或者有更好的解决方案吗?
我注意到ObservableCollection
在WPF中只通过添加或删除列表中的项目来反映GUI中的更改,而不是通过编辑它.
这意味着我必须编写自定义类MyObservableCollection.这种行为的原因是什么?
谢谢
我需要能够处理WPF StackPanel上的双击和单击事件.但是没有StackPanel的DoubleClick事件.我想在这两个EventHandler中做两个不同的操作.
知道怎么做吗?
谢谢
我在表单中有大约100个TextBox.如果它们是十进制的,我需要验证它们.这有效,但它太冗长了,我不想在XAML中用800代替100行.
<TextBox.Text>
<Binding Path="MyPath" UpdateSourceTrigger="PropertyChanged" Stringformat="{}{0:N}" NotifyOnValidationError="True">
<Binding.ValidationRules>
<myRulesNamespace:MyValidationRule ValidationType="decimal" />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
Run Code Online (Sandbox Code Playgroud)
有没有办法如何将它重写为这样的简短形式?:
Text="{Binding MyPath, UpdateSourceTrigger='PropertyChanged', StringFormat='{}{0:N}', NotifyOnValidationError=True, ValidationRules NOW WHAT?}"
Run Code Online (Sandbox Code Playgroud) wpf ×8
validation ×2
.net ×1
binding ×1
clear ×1
click ×1
components ×1
generics ×1
mouseevent ×1
multitrigger ×1
resources ×1
stackpanel ×1
templates ×1
textbox ×1
triggers ×1
window ×1
winforms ×1