Wpf画布背景图像不显示本地路径中的选定图像
XAML代码
<Canvas x:Name="LayoutRoot" Margin="485,24,0,0" HorizontalAlignment="Left" Width="341" Height="506" VerticalAlignment="Top">
<Canvas.Background>
<ImageBrush ImageSource="{Binding BGImage}"/>
</Canvas.Background>
</Canvas>
Run Code Online (Sandbox Code Playgroud)
MVVM代码
private String _BGImage = @"?C:/Users/sam/Desktop/photo-5.jpg";
public String BGImage
{
get
{
return this._BGImage;
}
set
{
this._BGImage = value;
NotifyPropertyChanged("BGImage");
}
}
Run Code Online (Sandbox Code Playgroud)
为什么这个图像不显示在画布背景上
出现的问题是,每当ComboBox更改 WPF ItemsSource 属性时,SelectedItem 属性就会设置为 null。
重现问题的要求:
实际上我想在Datagrid模板中绑定Combobox,Combobox集合存在于视图模型中,当我更改第一列属性时,其他行组合框项目变为空。
我该如何解决这个问题?
这是我的 XAML 代码:
<TextBox HorizontalAlignment="Left" Height="24" Margin="168,352,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="280">
<TextBox.Resources>
<sys:Double x:Key="fixedValue">2</sys:Double>
</TextBox.Resources>
<TextBox.Text>
<MultiBinding Converter="{StaticResource DoubleConverter}">
<Binding Path="RM.SpecificGravity"/>
<Binding Source="{StaticResource fixedValue}"/>
</MultiBinding>
</TextBox.Text>
</TextBox>
Run Code Online (Sandbox Code Playgroud)
这给了我这个错误:
双向绑定需要 Path 或 XPath。
这是什么原因造成的,我该如何解决?
如何在
没有第一次收藏的情况下将ObservableCollection物品复制到另一个ObservableCollection?此处ObservableCollection项目值更改会影响两个集合.
码
private ObservableCollection<RateModel> _AllMetalRate = new ObservableCollection<RateModel>();
private ObservableCollection<RateModel> _MetalRateOnDate = new ObservableCollection<RateModel>();
public ObservableCollection<RateModel> AllMetalRate
{
get { return this._AllMetalRate; }
set
{
this._AllMetalRate = value;
NotifyPropertyChanged("MetalRate");
}
}
public ObservableCollection<RateModel> MetalRateOnDate
{
get { return this._MetalRateOnDate; }
set
{
this._MetalRateOnDate = value;
NotifyPropertyChanged("MetalRateOnDate");
}
}
foreach (var item in MetalRateOnDate)
AllMetalRate.Add(item);
Run Code Online (Sandbox Code Playgroud)
造成这种情况的原因是什么?如何解决?