我有一个WPF应用程序。
我有一张用户可以点击的图片,并选择要上传的其他图片。
我希望能够做的是允许用户选择“无”或“空”,以便用户可以选择无图像,并且现有加载的图像将被清除。但是,如果用户选择“取消”,我希望保留现有的加载图像。
可以吗?
我的加价:
<Button Cursor="Hand" ToolTip="Click here to Add logO Image!" x:Name="btnLogo" Style="{DynamicResource NoChromeButton}" Margin="1,0,0,20" Click="btnLogo_Click">
<Image x:Name="WORK_SHEET_COMPANY_LOGO" Source="/InformedWorkerClient;component/Images/CompanyLogo.png" Stretch="Fill" Height="74" Width="300"/>
</Button>
我的代码:
private void btnLogo_Click(object sender, RoutedEventArgs e)
{
try
{
Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog();
if (ofd.ShowDialog() == true)
{
//either load new image or clear existing one
}
}
catch (Exception ex)
{
/deal with any errors
}
答案 0 :(得分:0)
据我所知,您希望用户能够点击某些内容将图像设置为空。如果是这种情况,您可以始终拥有与表单背景颜色相同的图像,或者此图片位于表单上的图像。然后你可以将图像设置为那样,那样看起来就像那里没有图像。