C# 绑定和解码PixelWidth属性
有人知道为什么绑定不适用于DecodePixelWidth属性吗?当我通过xml进行设置时——一切正常——我看到了缩放后的图像。当我使用绑定时,图像不会缩放C# 绑定和解码PixelWidth属性,c#,silverlight,windows-phone-8,C#,Silverlight,Windows Phone 8,有人知道为什么绑定不适用于DecodePixelWidth属性吗?当我通过xml进行设置时——一切正常——我看到了缩放后的图像。当我使用绑定时,图像不会缩放 <Image VerticalAlignment="Top" Width="2292" Stretch="None"> <Image.Source> <BitmapImage UriSource="{Binding Src}" DecodePixelWidth="{Binding De
<Image VerticalAlignment="Top" Width="2292" Stretch="None">
<Image.Source>
<BitmapImage UriSource="{Binding Src}" DecodePixelWidth="{Binding DecodePixelWidth}" />
</Image.Source>
</Image>
public int DecodePixelWidth
{
get
{
return _decodePixelWidth;
}
set
{
if (value != _decodePixelWidth)
{
_decodePixelWidth = value;
NotifyPropertyChanged("DecodePixelWidth");
}
}
}
公共像素宽度
{
得到
{
返回像素宽度;
}
设置
{
如果(值!=\u解码像素宽度)
{
_解码像素宽度=值;
NotifyPropertyChanged(“解码像素宽度”);
}
}
}
谢谢 我也遇到过同样的问题,我发现这个解决方案对我很有效 在我的MVVM WPF应用程序中,我想使用app.config中存储的值调整位图图像的大小。因此,为此,我尝试将Image.Height属性和BitmapImage.DecodePixelHeight直接绑定到我的ViewModel,如下所示: 在app.config中
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="DocumentsToBeFiledImageHeight" value="240"/>
<add key="DocumentsToBeFiledImageDecodePixelHeight" value="240"/>
</appSettings>
</configuration>
这个密码呢
<Image Grid.Row="0" Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.DocumentsToBeFiledImageHeight, UpdateSourceTrigger=PropertyChanged}">
<Image.Source>
<BitmapImage DecodePixelHeight="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.DocumentsToBeFiledImageDecodePixelHeight, UpdateSourceTrigger=PropertyChanged}"
UriSource="{Binding Path=FullName}" />
</Image.Source>
</Image>
DocumentsToBeFiledImageHeight=Convert.ToDouble(ConfigurationManager.AppSettings[“DocumentsToBeFiledImageHeight”])
DocumentsToBeFiledImageDecodePixelHeight=Convert.ToInt32(ConfigurationManager.AppSettings[“DocumentsToBeFiledImageDecodePixelHeight”])
然后在XAML中,我添加了以下代码
<Image Grid.Row="0" Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.DocumentsToBeFiledImageHeight, UpdateSourceTrigger=PropertyChanged}">
<Image.Source>
<BitmapImage DecodePixelHeight="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.DocumentsToBeFiledImageDecodePixelHeight, UpdateSourceTrigger=PropertyChanged}"
UriSource="{Binding Path=FullName}" />
</Image.Source>
</Image>
不幸的是,它不起作用,似乎DecodePixelHeight属性设置不正确。
因此,我尝试直接从app.config恢复该值。我已经在app.config文件的用户设置部分添加了这些参数
<userSettings>
<Agest.AO.Client.Properties.Settings>
<setting name="DocumentsToBeFiledImageDecodePixelHeight" serializeAs="String">
<value>240</value>
</setting>
<setting name="DocumentsToBeFiledImageHeight" serializeAs="String">
<value>240</value>
</setting>
</Agest.AO.Client.Properties.Settings>
</userSettings>
240
240
我以这种方式更改了XAML代码
xmlns:localme="clr-namespace:Agest.AO.Client.Properties"
<Image Grid.Row="0" Height="{Binding Source={x:Static localme:Settings.Default}, Path=DocumentsToBeFiledImageHeight, Mode=OneWay}">
<Image.Source>
<BitmapImage DecodePixelHeight="{Binding Source={x:Static localme:Settings.Default}, Path=DocumentsToBeFiledImageDecodePixelHeight, Mode=OneWay}"
UriSource="{Binding Path=FullName}" />
</Image.Source>
</Image>
xmlns:localme=“clr命名空间:Agest.AO.Client.Properties”
现在它可以工作了,我可以直接在配置文件中设置值
问候