我想做一个类似在Facebook上查看图像的模拟。当您单击图像并在弹出窗口中打开它时,主要问题是带有图片链接的源是集合中的另一个用户控件。 / p>
因此,我对此用户控件具有调光功能。
<Grid Background="#33000000" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid HorizontalAlignment="Center" VerticalAlignment="Center" Background="#FFFFFF" MinHeight="100" MinWidth="200">
<Grid.RowDefinitions>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="35"></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Background="#EEEEEE">
<Label Content="{Binding Title}" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
<Grid Grid.Row="1" Margin="10,20">
<Image Source="{Binding ImageURI}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</Grid>
<Grid Grid.Row="2" Background="#EEEEEE">
<Button Content="OK" Command="{Binding CloseCommand}" Width="80" Height="25" />
</Grid>
</Grid>
</Grid>
还有VM
public class PopupVM : ViewModelBase
{
private bool _isOpen;
public string ImageURI { get; set; }
public string Title { get; set; }
public bool IsOpen { get { return _isOpen; } set { _isOpen = value; RaisePropertyChanged("IsOpen"); } }
private void ClosePopup()
{
IsOpen = false;
}
public RelayCommand CloseCommand
{
get;
private set;
}
public PopupVM()
{
CloseCommand = new RelayCommand(() => ClosePopup());
}
}
在页面上使用用户控件
<local:PopupUserControl Visibility="{Binding popupVM_Instance.IsOpen, Converter={StaticResource BoolToVis}}" DataContext="{Binding popupVM_Instance}"/>
另一个带有图像源的用户控件的模型。集合,该集合绑定到ItemsControl
public class DialogMessageModel : ConversationModel
{
public ImageAttach Image { get; set; }
public bool HasImage => Image != null;
public bool HasMessage => Message != null;
public RelayCommand OpenImageCommand
{
get;
private set;
}
private void OpenImage()
{
TestVM.popupVM_Instance.ImageURI = Image.ImageURI;
TestVM.popupVM_Instance.IsOpen = true;
}
}
页面的VM具有PopupVM的实例,其他控件可以获取访问权限来打开它
public static PopupVM popupVM_Instance { get; set; }
public TestVM()
{
popupVM_Instance = new PopupVM();
}
打开不起作用。从开始就可见。如果单击按钮,也不要隐藏。我也使用MVVMLight。