我已經嘗試在MainWindow屬性的ResizeMode中導出資源,認爲數據可能與我的Window2 ResizeMode屬性綁定,但它與抓取和拖動位置/值不匹配,它只是匹配屬性值,在這種情況下是我分配給MainWindow的'CanResizeWithGrip'。所以我最終得到了兩個窗口的控制權,並且Window2與MainWindow的調整大小不匹配。我想自動縮小/放大我的Window2,當我點擊並拖動MainWindow上的大小調整。我無法真正掌握LocationChanged或SizeChanged句柄,以及在這種情況下應該如何使用它們。 我的MainWindow有一個視頻文件飼料與VLC插件,我的Window2有一個透明的背景,覆蓋切換按鈕和退出按鈕。如果有人能提供幫助,任何建議/明確的例子都會有幫助。同步第二個窗口大小以匹配主窗口大小
主窗口:
namespace VLC_Test
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
AxAXVLC.AxVLCPlugin vlcPlayer = new AxAXVLC.AxVLCPlugin();
public MainWindow()
{
InitializeComponent();
WFH1.Child = vlcPlayer;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Window2 win2 = new Window2();
win2.Show();
string file1 = @"C:\Users\Username\Desktop\drop.avi";
vlcPlayer.addTarget("file:///" + file1, null, AXVLC.VLCPlaylistMode.VLCPlayListReplaceAndGo, 0);
vlcPlayer.play();
}
}
}
XAML:
<Window x:Class="VLC_Test.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" SizeToContent="WidthAndHeight"
WindowStartupLocation="Manual"
Top="0" Left="7" AllowsTransparency="False" WindowStyle="None" Loaded="Window_Loaded" Topmost="True" ShowInTaskbar="False" BorderThickness="0" ResizeMode="CanResizeWithGrip">
<Window.Background>
<SolidColorBrush Opacity="0" Color="White"/>
</Window.Background>
<Grid Width="Auto" Height="Auto">
<WindowsFormsHost Height="495" Width="550" HorizontalAlignment="Left" Name="WFH1" VerticalAlignment="Top" Margin="-11,-24,0,0" ChildChanged="WFH1_ChildChanged" />
</Grid>
</Window>
窗口2:
namespace VLC_Test
{
/// <summary>
/// Interaction logic for Window2.xaml
/// </summary>
public partial class Window2 : Window
{
public Window2()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
}
private void button2_Click(object sender, RoutedEventArgs e)
{
this.Close();
App.Current.Shutdown();
}
}
}
XAML:
<Window x:Class="VLC_Test.Window2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window2" Height="495" Width="550"
WindowStartupLocation="Manual"
Top="0" Left="7" AllowsTransparency="True" WindowStyle="None" Topmost="True" >
<Window.Background>
<SolidColorBrush Opacity="0" />
</Window.Background>
<Window.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
</Window.Resources>
<Grid Width="Auto" Height="Auto">
<ToggleButton Content="Crosshair" Height="39" HorizontalAlignment="Right" Margin="0,0,125,12" Name="Button1" VerticalAlignment="Bottom" Width="58" Click="button1_Click" IsChecked="False" DataContext="{Binding}"/>
<Button Content="Exit" Height="39" HorizontalAlignment="Right" Margin="0,0,49,12" Name="button2" VerticalAlignment="Bottom" Width="58" Click="button2_Click" />
<Canvas Background="Transparent" Height="200" Width="200" HorizontalAlignment="Center" Margin="0,0,0,0" Name="Canvas1" VerticalAlignment="Center" Visibility="{Binding IsChecked, ElementName=Button1, Converter={StaticResource BooleanToVisibilityConverter}}">
<Line X1="100" Y1="0" X2="100" Y2="75" Stroke="Red" StrokeThickness="0.95" />
<!--Top long vertical line> /-->
<Line X1="100" Y1="95" X2="100" Y2="105" Stroke="Red" StrokeThickness="0.95" />
<!--Crosshair vertical line> /-->
<Line X1="100" Y1="125" X2="100" Y2="200" Stroke="Red" StrokeThickness="0.95" />
<!--Bottom long vertical line> /-->
<Line X1="0" Y1="100" X2="75" Y2="100" Stroke="Red" StrokeThickness="0.75" />
<!--Left long horizontal line> /-->
<Line X1="95" Y1="100" X2="105" Y2="100" Stroke="Red" StrokeThickness="0.75" />
<!--Crosshair horizontal line> /-->
<Line X1="125" Y1="100" X2="200" Y2="100" Stroke="Red" StrokeThickness="0.75" />
</Canvas>
</Grid>
</Window>
任何人都可以幫忙嗎? – cheapkid1
[Trigger](http://msdn.microsoft.com/ru-ru/library/system.windows.trigger(v = vs.110).aspx)是你需要的,也是[EventTrigger](http: //msdn.microsoft.com/ru-ru/library/system.windows.eventtrigger(v=vs.110).aspx) – Grundy
我不認爲這會工作,除非你有一個調整窗口大小的例子,isn'觸發和EventTrigger只是一個布爾改變框架元素的外觀?不動態大小更改屬性...?如果可能的話,我不確定該怎麼做。 – cheapkid1