在WPF中放大屏幕的特定部分 [英] Zooming in specific part of screen in WPF

查看:114
本文介绍了在WPF中放大屏幕的特定部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现一个具有多个行和多个列的小型WPF应用程序.第0行和第0列包含MediaElement,第1行和第0列包含全屏按钮.当用户单击全屏按钮时,我想切换到只有两行一列的网格.第0行和第0列将占据MediaElement内部的大部分屏幕空间,而第1行和第0列将显示一个最小化按钮,它将使原始UI返回. 在传统的窗口中,我们用来切换托管WindowsMedia Player的全屏面板的可见性以实现此行为.如何在WPF中实现这一目标?

I am implementing one small WPF application which has multiple rows and multiple columns. 0th row and 0th column contains a MediaElement and 1st row and 0th column contains a full screen button. When user clicks on full screen button I want to switch to a gird which has only two rows and one column. 0th row and 0th column will occupy most of the screen space having inside MediaElement and 1st row and 0th column will show a minimize button which will bring original UI back. In traditional windows we were used to toggle visibility of a full screen panel hosting WindowsMedia player to achieve this behavior. How can I achieve this in WPF?

添加我的XAML代码.

Adding my XAML code.

<Window x:Class="LearnEnglish.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow"
        Height="350"
        Width="525">
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="5*" />
      <RowDefinition Height="1*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="5*" />
      <ColumnDefinition Width="2*" />
      <ColumnDefinition Width="2*" />
      <ColumnDefinition Width="1*" />
    </Grid.ColumnDefinitions>
    <MediaElement LoadedBehavior="Manual"
                  Name="me"
                  Source="C:\Users\Pritam\Documents\Freecorder\Screen\Northern Ireland Scene 1  LearnEnglish  British Council.wmv"
                  Volume="{Binding ElementName=txtVolume,Path=Text}"
                  Grid.ColumnSpan="2">

    </MediaElement>

    <Button Click="Button_Click"
            Grid.Row="1"
            Margin="4">Play</Button>
    <Button Click="Button_Click"
            Grid.Row="1"
            Grid.Column="1"
            Margin="4">Full Screen</Button>
    <Button Click="Button_Click"
            Grid.Row="1"
            Grid.Column="1"
            Margin="4"
            Visibility="Hidden">Restore</Button>

  </Grid>
</Window>

当用户单击全屏"按钮时,我希望我的"MediaElement"占据大部分屏幕(通过隐藏所有其他控件),并在屏幕的右下角保留恢复"按钮.

When user clicks on 'Full Screen' button I want my 'MediaElement' to occupy most of the scree space ( by hiding all other controls ) and leaving 'Restore' button in the bottom-right hand side of screen.

关于, 赫曼特(Hemant)

Regards, Hemant

推荐答案

您可以在XAML中完全使用ToggleButton并在其IsChecked属性上使用触发器来完全做到这一点,该触发器可设置您不需要的所有列/行的宽度/高度希望看到为0.使用x:Name命名要更改的元素,这将使编写触发器更加容易.

You can do that completely in XAML by using a ToggleButton and a trigger on its IsChecked property which sets the width / height of all columns / rows you don't want to see to 0. Use x:Name to name the elements you want to change, that will make it easier to write the Trigger.

为了能够访问所有控件,您应该在包含所有其他控件的父控件上定义触发器,例如在UserControl,面板,DataTemplate或ControlTemplate中.为了访问不同控件上的属性,请将其名称用于设置器上的TargetName属性.触发器本身也有一个对应的SourceName属性,因此您不必在ToggleButton本身上定义触发器.

In order to be able to access all controls, you should define the trigger on a parent control which contains all the other controls, e.g. in a UserControl, a panel, a DataTemplate or ControlTemplate. In order to access the properties on different controls, use their names for the TargetName property on the setters. There is also a corresponding SourceName property on Trigger itself, so you don't have to define the Trigger on the ToggleButton itself.

这篇关于在WPF中放大屏幕的特定部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆