我想拥有带有选项卡控件的主WPF表单,其中每个选项卡包含一个独立的WPF表单.这些形式并不相互依赖,所以我认为将它们分开开发更简单,然后将它们嵌入到主形式中.
表单数量是已知的,因此不需要动态插件系统.
TextBox 应该显示某些访问权限的隐藏金额。我创建了一个转换器类(从 IValueConverter 继承)来通过实现 convert 方法来处理屏蔽。
public object Convert(object value, Type targetType, object parameter,
CultureInfo culture)
Run Code Online (Sandbox Code Playgroud)
如果需要屏蔽,则第三个参数为 true,否则为 false。
像这样调用:
CurrencyCOnverter converter = new CurrencyConverter();
this._textbox1.Text = converter.Convert(Amount, typeof(string), !this.IsSuperUser,
CurrentCulture).ToString();
Run Code Online (Sandbox Code Playgroud)
我在 UI 上有大约 12 个文本框。我没有在 12 个地方这样做,而是在 Resource 字典中定义了 DataTemplates,如下所示:
<DataTemplate x:Key="MaskNormalBackgroundTbx">
<TextBlock TextAlignment="Right" VerticalAlignment="Center"
TextWrapping="WrapWithOverflow"
Text="{Binding "Amount"
Converter={StaticResource CurrencyDisplayConverter},
ConverterParameter=true}" />
</DataTemplate>
<DataTemplate x:Key="NoMaskNormalBackgroundTbx">
<TextBlock TextAlignment="Right" VerticalAlignment="Center"
TextWrapping="WrapWithOverflow"
Text="{Binding "Amount"
Converter={StaticResource CurrencyDisplayConverter},
ConverterParameter=false}" />
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)
我的问题:有没有一种方法可以通过创建自定义文本框来将此模板分配给文本框,就像我们为 ListBox 分配数据模板一样?
谢谢,
梅根。
我有两个私有列表需要在创建对象时初始化.第二个列表取决于第一个列表.我能这样做吗:
public class MyClass
{
private List<T> myList = new List<T>();
private ReadOnlyCollection<T> myReadOnlyList = myList.AsReadOnly;
...
}
Run Code Online (Sandbox Code Playgroud)
第二个列表是第一个只读包装.
我可以期望c#每次运行时都按此顺序执行这两行吗?
或者我应该将这个初始化放在构造函数中?
编辑:
抱歉愚蠢的问题.我试过了,编译器说:
Error 1 A field initializer cannot reference the
non-static field, method, or property...
Run Code Online (Sandbox Code Playgroud) 我有字符串,我想切断给定长度n的子串数组.我对余数不感兴趣(如果字符串的长度不能除以n而没有余数)
let ChopString (myString : string) n =
let res =
seq{
for i = 0 to myString.Length / n - 1 do
yield( String.sub myString (i*n) n )
}
|> Seq.to_array
res
Run Code Online (Sandbox Code Playgroud)
这是我能做的最好的事情.它看起来很难看.
是否有更好/更短的版本,也许没有for循环?