如何在数据不存在时隐藏字符串格式.请考虑此示例
<TextBlock Text="{Binding Amount, StringFormat=Total: {0:C}}" />
Run Code Online (Sandbox Code Playgroud)
在这种情况下,如果Amount为null,那么它将只显示Total:.如果Amount为null或为空,如何隐藏它
我绑定TextBlock.Visiblitiy了什么,我想设置Binding.TargetNullValue为Collapsed,我怎么能在XAML中做到?
这个如何将TargetNullValue设置为日期?在Silverlight中不起作用.(不x:Static).
在SQL中我可以这样做:
Select Coalesce(Property1, Property2, Property3, 'All Null') as Value
From MyTable
Run Code Online (Sandbox Code Playgroud)
如果Property1,2和3都为null,那么我得到'All Null'
我如何在XAML中执行此操作?我试过以下,但没有运气:
<Window.Resources>
<local:Item x:Key="MyData"
Property1="{x:Null}"
Property2="{x:Null}"
Property3="Hello World" />
</Window.Resources>
<TextBlock DataContext="{StaticResource MyData}">
<TextBlock.Text>
<PriorityBinding TargetNullValue="All Null">
<Binding Path="Property1" />
<Binding Path="Property2" />
<Binding Path="Property3" />
</PriorityBinding>
</TextBlock.Text>
</TextBlock>
Run Code Online (Sandbox Code Playgroud)
结果应该是'Hello World',而是'All Null'
我希望我的问题很明确.
我有一个wpf文本块,如下所示:
<TextBlock Text="{Binding [someViewModel].SomeVar.SomeSubVar.Name,
TargetNullValue='-'}"/>
Run Code Online (Sandbox Code Playgroud)
在我的viewmodel方面,我将拥有自己的逻辑,最终SomeVar.SomeSubVar将为null.
如果我想为此显示默认值,TextBlock我知道我可以声明并启动SomeVar.SomeSubVar并分配默认值,SomeVar.SomeSubVar.Name但我想TargetNullValue改用.我可以知道哪一部分是错的吗?
我正在使用WPF工具包的Calendar控件来允许用户选择日期.如果尚未选择日期,则SelectedDate绑定的属性为Null.这使日历默认为1月1日,AD.我想做点什么
SelectedDate="{Binding UserPickedDate, TargetNullValue=Today, Mode=TwoWay}"
Run Code Online (Sandbox Code Playgroud)
但是"今天"和"现在"都会引发绑定错误.我可以使用TargetNullValue将默认日期设置为今天或现在吗?
我有这个xaml文本框
<TextBox Text="{Binding ProdFilter.Min, Mode=OneWayToSource,
UpdateSourceTrigger=PropertyChanged, TargetNullValue=''}"
Width="50" DockPanel.Dock="Right" TabIndex="3" />
Run Code Online (Sandbox Code Playgroud)
绑定到此属性:
public double? Min
{
get { return min; }
set
{
if (value == null)
value = 0;
min = value;
OnPropertyChanged("Min");
}
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是,当程序启动或用户清除文本时,文本框的文本设置为"0".我不知道这种行为是否正确,因为我正在使用OneWayToSource,但我希望我的属性在文本为空时设置为null(并且文本保持为空!)
有任何想法吗?谢谢!
我在Data Repository类中有一个静态ObservableCollection.我用它来填充我的一个表单上的组合框(它需要能够包含一个表示NULL的空行).
我使用相同的ObservableCollection来填充DataGrid,所以我不想要实际的ObservableCollection中的空白项.我该怎么做呢?
哦,我想要这样做的原因是,如果我打开两个表单并从ObservableCollection中删除一个项目,它应该反映在两个列表中.
我有一个Listview和一个Textbox绑定到所选项目.当用户删除文本框中的值(这是一个双精度值)时,我收到以下错误: Value '' cannot be converted.所以我有TargetNullValue='',像这样:
<TextBox x:Name="textBoxVoltage" Text="{Binding Voltage, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, TargetNullValue=''}" />
Run Code Online (Sandbox Code Playgroud)
但我仍然得到错误......我做错了什么?谢谢.
我在使用Android从SQLite数据库获取空值时遇到问题.
我的数据库有10列.从第1列到第8列都填充了值.但是有几行,其中第9列和第10列中的值为空或某些数字.
我想查一下:
String selectQuery = "SELECT * FROM products WHERE barcodeId='" + id + "'";
Cursor myCursor = db.rawQuery(selectQuery, null);
if (myCursor.moveToFirst()) {
//checking to see if there is something in column 9
if(myCursor.getString(8) != null){
// do soemthing
}else {
// if there is nothing do something
}
//checking to see if there is something in column 10
if(myCursor.getString(9) != null){
// do soemthing
}else {
// if there is nothing do something
}
}
Run Code Online (Sandbox Code Playgroud)
有些人可以根据我的例子提供一个工作代码,我的表中有第9列和第10列.
简要说明也将受到欢迎.谢谢
wpf ×7
c# ×4
xaml ×4
binding ×3
data-binding ×2
android ×1
c#-4.0 ×1
calendar ×1
coalesce ×1
mvvm ×1
silverlight ×1
sqlite ×1
textblock ×1
wpftoolkit ×1