C# 使用IValueConverter调整绑定到数据源的图像大小
我有一个图像文件绑定到网格内的图像元素,如下所示C# 使用IValueConverter调整绑定到数据源的图像大小,c#,data-binding,winrt-xaml,ivalueconverter,C#,Data Binding,Winrt Xaml,Ivalueconverter,我有一个图像文件绑定到网格内的图像元素,如下所示 <FlipView x:Name="FlipView" ItemsSource="{Binding Source={StaticResource ItemsViewSource}}" SelectionChanged="FlipView_SelectionChanged"> <FlipView.ItemTemplate> <DataTemplate>
<FlipView x:Name="FlipView" ItemsSource="{Binding Source={StaticResource ItemsViewSource}}" SelectionChanged="FlipView_SelectionChanged">
<FlipView.ItemTemplate>
<DataTemplate>
<Grid SizeChanged="Grid_SizeChanged">
<Image Source="{Binding File, Converter={StaticResource ImageConverter}}" Stretch="None" />
</Grid>
</DataTemplate>
</FlipView.ItemTemplate>
</FlipView>
图像设置为“不拉伸”,因为我正在IValueConverter内部调整大小,以便小图像不会像素化,而大图像仍会缩小以适应屏幕
当我的应用程序大小更改时,如何触发IValueConverter重新计算当前显示的图像大小?实现INotifyPropertyChanged界面,当应用程序大小更改时,设置文件属性值
public PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = this.PropertyChanged;
if (handler != null)
{
var e = new PropertyChangedEventArgs(propertyName);
handler(this, e);
}
}
private String file;
public String File
{
get
{
return file;
}
set
{
file = value;
NotifyPropertyChanged("File");
}
}
对不起,我不明白。我将使用什么来处理PropertyChangedEvent?它是数据绑定框架的一部分,将处理有效的属性。我还必须在与PropertyChanged的绑定上设置UpdateSource。是的,确实如此,您需要更新数据源。