Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
usercontrol打开不同的windows c#_C#_Wpf - Fatal编程技术网

usercontrol打开不同的windows c#

usercontrol打开不同的windows c#,c#,wpf,C#,Wpf,您好,我在wpf中使用用户控件时遇到一些问题。我在用户控制中有一个图像。我想将此用户控件放置在包含一些地图的主窗口上。我正在将此用户控件(图像)放置在主窗口上。它们是10到15。我想通过单击此用户控件打开不同的窗口,此用户控件只是一个图像。但当我这样做的时候,它每次只显示相同的窗口。有没有办法让我只需要创建一个用户控件并多次使用它来打开不同的窗口。比如(window1、window2、window3)等等 请帮帮我。我会非常感激的 <UserControl xmlns="http://sc

您好,我在wpf中使用用户控件时遇到一些问题。我在用户控制中有一个图像。我想将此用户控件放置在包含一些地图的主窗口上。我正在将此用户控件(图像)放置在主窗口上。它们是10到15。我想通过单击此用户控件打开不同的窗口,此用户控件只是一个图像。但当我这样做的时候,它每次只显示相同的窗口。有没有办法让我只需要创建一个用户控件并多次使用它来打开不同的窗口。比如(window1、window2、window3)等等

请帮帮我。我会非常感激的

<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Demo.WindowsPresentation.CustomMarkers.CustomMarkerDemo"
Height="40" Width="30" Opacity="10">
    <Image MouseDown="clickit" Name="icon" Source="bigMarkerGreen.png" VerticalAlignment="Center" HorizontalAlignment="Center" />

据我所知,根据给定的信息,您希望在不同的窗口中打开此UserControl。我建议您创建一个窗口,并像下面那样将这个UserControl添加到其中

<Window x:Class="Demo.WindowsPresentation.CustomMarkers.win.winCustomMarker"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:marker="clr-namespace:Demo.WindowsPresentation.CustomMarkers"
        Title="Window" Height="345" Width="380">
    <Grid>
        <marker:CustomMarkerDemo></marker:CustomMarkerDemo>
    </Grid>
</Window>

在问题中放置一些相关代码我编辑了我的问题。这是用户控件。请包括您当前通过单击此用户控件打开窗口的部分。请看这里的打开主控件…但是如何通过放置单个用户控件打开不同的窗口打开这些不同的窗口的标准是什么窗户?我相信你只想在窗口中根据单击的图像打开不同的图像,不是吗?你没有理解我的意思。。无论我用了多少次,它都会打开同一个窗口。。我想使用单用户控件打开不同的窗口使用Ali的方式,但是检查用户单击的图钉并决定打开哪个窗口。只需使用上面相同的
clickit
方法,并添加一些
if()
语句来决定要打开哪个窗口。@dubstylee我真的不明白创建这么多窗口只是为了显示一个图像的目的。我们可以将点击的信息传递到我们的1窗口,并根据需要进行处理@AliBaig我同意,但OP希望有单独的窗口,所以有人建议他如何实现:)这不像我创建这么多窗口来显示一个图像..这个图像将像按钮一样工作。我想把这张图片放在有地图的主窗口上。。因此,每当单击此用户控件时,我都希望显示windows。。例如,如果把5个放在不同的位置,它应该会显示5个不同的窗口。。。只有一个用户控件。
<Window x:Class="Demo.WindowsPresentation.CustomMarkers.win.winCustomMarker"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:marker="clr-namespace:Demo.WindowsPresentation.CustomMarkers"
        Title="Window" Height="345" Width="380">
    <Grid>
        <marker:CustomMarkerDemo></marker:CustomMarkerDemo>
    </Grid>
</Window>
void clickit(object sender, MouseButtonEventArgs e)
{

    winCustomMarker customMarkerWindow = new winCustomMarker();
    //bind any information you want that you want to pass to your inner UserControl
    customMarkerWindow.show();
}