페이지/프레임에서 창으로의 WPF 통신
-
05-07-2019 - |
문제
프레임의 페이지를 탐색하는 간단한 WPF 앱을 구축했지만 프레임 중 하나는 사진 시청자이며 누군가가 그림을 두 번 클릭하면 전체 화면 (즉 프레임 외부)이됩니다.
WPF 에서이 작업을 수행하는 가장 좋은 방법은 무엇입니까?
해결책
당신은 자신에게 관습을 만들 수 있어야합니다 Routeduicommand, 아마도 "EnterfullScreen"이라고 불리는 것은 이미지 뷰어를 나타내는 페이지 내에서 발생할 수 있습니다. 당신은 단순히 기본 창에서 명령 바지를 연결하여 해당 명령이 발사 될 때마다 반응합니다. 분명히 "exitfullscreen"도 반대가 필요하므로 각 페이지가 전체 화면 모드를 종료하기위한 자체 UI를 제공 할 수 있습니다.
다음은 명령을 정의하고 연결하기위한 코드가 어떻게 보일지 모르는 것입니다.
public partial class MyWindow : Window
{
public static readonly RoutedUICommand EnterFullScreenCommand =
new RoutedUICommand("Enter fullscreen mode",
"EnterFullScreen",
typeof(MyWindow));
public static readonly RoutedUICommand ExitFullScreenCommand =
new RoutedUICommand("Exit fullscreen mode",
"ExitFullScreen",
typeof(MyWindow));
public MyWindow()
{
this.InitializeComponent();
this.CommandBindings.Add(
new CommandBinding(MyWindow.EnterFullScreenCommand,
(sender, args) =>
{
// logic to go fullscreen here
},
(sender, args) =>
{
args.CanExecuted =
// am I already fullscreen?
}));
this.CommandBindings.Add(
new CommandBinding(MyWindow.ExitFullScreenCommand,
(sender, args) =>
{
// logic to exit fullscreen here
},
(sender, args) =>
{
args.CanExecuted =
// am I fullscreen right now?
}));
}
그런 다음 페이지에서 다음과 같이이 명령을 사용합니다.
<Button Command="{x:Static myNS:MyWindow.EnterFullScreenCommand}" />
제휴하지 않습니다 StackOverflow