根据您放入另一个 WPF 中的信息在 WPF 中放入一个值/打开文件

Put a value / open files in a WPF from informations you put in another WPF

我是从 C# 开始的,我的问题是他在跟进 :

我想使用带有按钮、文本框等的 WPF... 来控制(在其中显示信息和视频)另一个 WPF。

但我找不到如何与其他 WPF 正确交互。

我的 WPF 代码 windows :

<Window x:Class="WPF_AVC.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:WPF_AVC"
    mc:Ignorable="d"
    Title="ConfiguratorAVC" Height="350" Width="525">
<Grid Background="Black">
    <TextBox x:Name="textBox" HorizontalAlignment="Center" Height="22" Margin="0,48,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Background="Black" BorderBrush="#FF707070" Foreground="#FF707071" SelectionBrush="Black" TextChanged="textBox_TextChanged" KeyDown="OnKeyDownHandler"/>
    <TextBlock x:Name="textBlock" HorizontalAlignment="Center" Margin="0,32,0,0" TextWrapping="Wrap" Text="Entrez un mot" VerticalAlignment="Top" Width="120" Foreground="#FF707071" TextAlignment="Center"/>
    <Button x:Name="generate_words_btn" Content="Generer hologramme" HorizontalAlignment="Center" Margin="0,76,0,0" VerticalAlignment="Top" Width="120" Background="Black" Foreground="#FF707070" Click="generate_words_btn_Click"/>
    <Border Margin="0,267,-0.2,22" HorizontalAlignment="Center">
        <Grid>
            <Button x:Name="Pay_btn" Content="►" HorizontalAlignment="Center" Margin="0,0,243,0" VerticalAlignment="Top" Width="74" Background="Black" FontWeight="Bold" Foreground="#FF707071" HorizontalContentAlignment="Center" Height="30" Click="Pay_btn_Click" OpacityMask="Black">
                <Button.BindingGroup>
                    <BindingGroup/>
                </Button.BindingGroup>
            </Button>
            <Button x:Name="Stop_btn" Content="■" HorizontalAlignment="Center" Margin="160,0,81,0" VerticalAlignment="Top" Width="76" Background="Black" FontWeight="Bold" Foreground="#FF707071" HorizontalContentAlignment="Center" Height="30" Click="Stop_btn_Click">
                <Button.BindingGroup>
                    <BindingGroup/>
                </Button.BindingGroup>
            </Button>
            <Button x:Name="Pause_btn" Content="❚❚" HorizontalAlignment="Center" Margin="79,0,162,0" VerticalAlignment="Center" Width="76" Background="Black" FontWeight="Bold" Foreground="#FF707071" HorizontalContentAlignment="Center" Height="30" Click="Pause_btn_Click">
                <Button.BindingGroup>
                    <BindingGroup/>
                </Button.BindingGroup>
            </Button>
            <Button x:Name="Open_btn" Content="Open" HorizontalAlignment="Center" Margin="241,0,0,0" VerticalAlignment="Top" Width="76" Background="Black" FontWeight="Bold" Foreground="#FF707071" HorizontalContentAlignment="Center" Height="30" Click="Open_btn_Click" OpacityMask="Black">
                <Button.BindingGroup>
                    <BindingGroup/>
                </Button.BindingGroup>
            </Button>
        </Grid>
    </Border>
    <ListBox x:Name="listBox" HorizontalAlignment="Left" Height="84" Margin="53,120,0,0" VerticalAlignment="Top" Width="100" Background="Black" BorderBrush="#FF707070">
        <ListBoxItem Content="Iron Man" Foreground="#FF707071" Selected="ListBoxItem_Selected"/>
        <ListBoxItem Content="Daft Punk" Foreground="#FF707071" Selected="ListBoxItem_Selected_1"/>
        <ListBoxItem Content="Link Shield" Foreground="#FF707071" Selected="ListBoxItem_Selected_2"/>
        <ListBoxItem Content="Anonymous" Foreground="#FF707071" Selected="ListBoxItem_Selected_3"/>
    </ListBox>

</Grid>

<Window x:Name="holoAvcWindow" x:Class="WPF_AVC.DisplaynWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:WPF_AVC"
    mc:Ignorable="d"
    Title="HoloAVC" Height="950.333" Width="1600" Background="Black" WindowStyle="ToolWindow" SnapsToDevicePixels="True" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" >
<Window.BindingGroup>
    <BindingGroup/>
</Window.BindingGroup>
<Grid>
    <MediaElement x:Name="mediaElement" HorizontalAlignment="Center" Height="720" Margin="0" VerticalAlignment="Center" Width="1280"/>
    <Grid Margin="336,0,336,50">
        <MediaElement x:Name="videoDisplayElement" Height="300" VerticalAlignment="Top" Margin="0,311,622,0" RenderTransformOrigin="0.5,0.5" OpacityMask="Black">
            <MediaElement.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform Angle="-90"/>
                    <TranslateTransform/>
                </TransformGroup>
            </MediaElement.RenderTransform>
        </MediaElement>
        <MediaElement x:Name="videoDisplayElement_Copy" HorizontalAlignment="Center" Height="300" Width="300" Margin="311,622,311,0" RenderTransformOrigin="0.5,0.5" OpacityMask="Black" VerticalAlignment="Top">
            <MediaElement.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform Angle="180"/>
                    <TranslateTransform/>
                </TransformGroup>
            </MediaElement.RenderTransform>
        </MediaElement>
        <MediaElement x:Name="videoDisplayElement_Copy1" HorizontalAlignment="Center" Height="300" VerticalAlignment="Top" Width="300" Margin="311,0" OpacityMask="Black"/>
        <MediaElement x:Name="videoDisplayElement_Copy2" HorizontalAlignment="Left" Height="300" VerticalAlignment="Top" Width="300" Margin="622,311,0,0" RenderTransformOrigin="0.5,0.5" OpacityMask="Black">
            <MediaElement.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform Angle="+90"/>
                    <TranslateTransform/>
                </TransformGroup>
            </MediaElement.RenderTransform>
        </MediaElement>
        <TextBlock x:Name="textBlock2" HorizontalAlignment="Left" Margin="60,371,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="White" FontSize="48" Width="300" Height="180" RenderTransformOrigin="0.5,0.5" TextAlignment="Center">
            <TextBlock.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform Angle="-90"/>
                    <TranslateTransform/>
                </TransformGroup>
            </TextBlock.RenderTransform>
        </TextBlock>
    </Grid>
    <TextBlock x:Name="textBlock1" HorizontalAlignment="Left" Margin="647,120,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="White" FontSize="48" Width="300" Height="180" TextAlignment="Center"/>
    <TextBlock x:Name="textBlock3" HorizontalAlignment="Left" Margin="898,371,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="White" FontSize="48" Width="300" Height="180" RenderTransformOrigin="0.5,0.5" TextAlignment="Center">
        <TextBlock.RenderTransform>
            <TransformGroup>
                <ScaleTransform/>
                <SkewTransform/>
                <RotateTransform Angle="90"/>
                <TranslateTransform/>
            </TransformGroup>
        </TextBlock.RenderTransform>
    </TextBlock>
    <TextBlock x:Name="textBlock4" HorizontalAlignment="Left" Margin="647,622,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="White" FontSize="48" Width="300" Height="180
               " RenderTransformOrigin="0.5,0.5" TextAlignment="Center">
        <TextBlock.RenderTransform>
            <TransformGroup>
                <ScaleTransform/>
                <SkewTransform/>
                <RotateTransform Angle="180"/>
                <TranslateTransform/>
            </TransformGroup>
        </TextBlock.RenderTransform>
    </TextBlock>
</Grid>

我知道上面的代码没有优化。

我想了解如何通过第一个 WPF 中的输入在第二个 WPF 中显示视频。

谢谢!

您可以做很多事情。如果"play"按钮是打开第二个wpf你可以在Play_btn:

中添加click事件
private void Play_btn_Click(object sender, RoutedEventArgs e)
{
holoAvcWindow avc = new holoAvcWindow();
avc.Show();
this.Close();
}

或者你可以做 .ShowDialog(); 而不要写 this.Close(); 如果你想都打开,但用户将无法使用第一个屏幕,除非他关闭第二个屏幕。或者只删除 this.Close(); 并保留 .Show();。这样用户就可以同时使用两者。

所以我们有:

  • .Show() 和 this.Close():将关闭第一个屏幕并显示 holoAcvWindow。

  • .Show() 没有 this.Close() 不推荐:将保持打开状态,用户将能够同时使用两者。这不是最好的选择,因为如果有一个按钮可以打开第二个 window,用户可以根据需要打开 1000 个 windows。

  • .ShowDialog():将打开第二个 holoAvcWindow。将保持 MainWindow 打开,但除非 holoAvcWindow 关闭,否则用户将无法使用。

此外,如果您需要第一个屏幕向第二个屏幕发送任何内容,例如 url,只需创建一个需要参数的初始化方法。喜欢:

public holoAvcWindow(string url)
{
    InitializeComponent();
}

并像这样调用第二个屏幕:

private void Play_btn_Click(object sender, RoutedEventArgs e)
{
      holoAvcWindow avc = new holoAvcWindow(url);
      avc.Show();
      this.Close();
}

如果你想在加载程序时同时打开两个屏幕,将此添加到 main 的初始化方法中 window:

      holoAvcWindow avc = new holoAvcWindow(url);
      avc.Show();

应该是这样的:

public MainWindow()
{
    InitializeComponent();
    holoAvcWindow avc = new holoAvcWindow();
    avc.Show();
}