UWP 从 SplitView 设置 ImageSource
UWP set ImageSource from SplitView
我有一个小 SplitView
应用程序,现在我将在 mySplitpanel
的 page2
上设置 ImageSource
。
我如何才能访问所有参数,例如 SetSource 或 Visible?
这是我的代码
Mainpage.xaml
<Page
x:Class="App1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" Width="938.137">
<SplitView x:Name="MySplitView" DisplayMode="CompactOverlay" IsPaneOpen="False"
CompactPaneLength="50" OpenPaneLength="150">
<SplitView.Pane>
<StackPanel Background="Gray">
<Button x:Name="HamburgerButton" FontFamily="Segoe MDL2 Assets" Content=""
Width="50" Height="50" Background="Transparent" Click="HamburgerButton_Click"/>
<StackPanel Orientation="Horizontal">
<Button x:Name="MenuButton1" FontFamily="Segoe MDL2 Assets" Content=""
Width="50" Height="50" Background="Transparent" Click="MenuButton1_Click"/>
<TextBlock Text="Button 1" FontSize="18" VerticalAlignment="Center" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Button x:Name="MenuButton2" FontFamily="Segoe MDL2 Assets" Content=""
Width="50" Height="50" Background="Transparent" Click="MenuButton2_Click"/>
<TextBlock Text="Button 2" FontSize="18" VerticalAlignment="Center" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Button x:Name="MenuButton3" FontFamily="Segoe MDL2 Assets" Content=""
Width="50" Height="50" Background="Transparent" Click="MenuButton3_Click"/>
<TextBlock Text="Button 3" FontSize="18" VerticalAlignment="Center" />
</StackPanel>
</StackPanel>
</SplitView.Pane>
<Frame x:Name="myFrame" />
</SplitView>
</Page>
Mainpage.xaml.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
namespace App1
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
myFrame.Navigate(typeof(Page1));
}
private void MenuButton1_Click(object sender, RoutedEventArgs e)
{
myFrame.Navigate(typeof(Page2));
}
private void HamburgerButton_Click(object sender, RoutedEventArgs e)
{
MySplitView.IsPaneOpen = !MySplitView.IsPaneOpen;
}
private void MenuButton2_Click(object sender, RoutedEventArgs e)
{
myFrame.Navigate(typeof(Page1)); //Home
}
private void MenuButton3_Click(object sender, RoutedEventArgs e)
{
//set image source at page2.myImagePage2
// ??
}
}
}
Page2.xaml
<Page
x:Class="App1.Page2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="#FFE03535">
<Image x:Name="myImagePage2" HorizontalAlignment="Left" Height="116" Margin="81,112,0,0" VerticalAlignment="Top" Width="175" Source="Assets/LockScreenLogo.png"/>
</Grid>
</Page>
我想将 Page2.myImagePage2 中的 ImageSource
从 MenuButton3_Click
更改为
如何访问 page2
中的函数?
该函数设置 Page2
上的 Visibilty
个项目。
我可以访问该功能并且项目变得不可见吗?
您可以使用 Page2
(Page2.xaml.cs
) 的代码隐藏来创建一个 public
方法来修改可见性(如 public void HideImage()
或 public void ChangeImageSource()
).
现在要在 Click
处理程序中获取当前页面,请使用 Frame.Content
属性:
private void MenuButton3_Click(object sender, RoutedEventArgs e)
{
var page = myFrame.Content as Page2;
if ( page != null )
{
//do something like calling your custom public method
//page.HideImage();
}
}
我有一个小 SplitView
应用程序,现在我将在 mySplitpanel
的 page2
上设置 ImageSource
。
我如何才能访问所有参数,例如 SetSource 或 Visible?
这是我的代码
Mainpage.xaml
<Page
x:Class="App1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" Width="938.137">
<SplitView x:Name="MySplitView" DisplayMode="CompactOverlay" IsPaneOpen="False"
CompactPaneLength="50" OpenPaneLength="150">
<SplitView.Pane>
<StackPanel Background="Gray">
<Button x:Name="HamburgerButton" FontFamily="Segoe MDL2 Assets" Content=""
Width="50" Height="50" Background="Transparent" Click="HamburgerButton_Click"/>
<StackPanel Orientation="Horizontal">
<Button x:Name="MenuButton1" FontFamily="Segoe MDL2 Assets" Content=""
Width="50" Height="50" Background="Transparent" Click="MenuButton1_Click"/>
<TextBlock Text="Button 1" FontSize="18" VerticalAlignment="Center" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Button x:Name="MenuButton2" FontFamily="Segoe MDL2 Assets" Content=""
Width="50" Height="50" Background="Transparent" Click="MenuButton2_Click"/>
<TextBlock Text="Button 2" FontSize="18" VerticalAlignment="Center" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Button x:Name="MenuButton3" FontFamily="Segoe MDL2 Assets" Content=""
Width="50" Height="50" Background="Transparent" Click="MenuButton3_Click"/>
<TextBlock Text="Button 3" FontSize="18" VerticalAlignment="Center" />
</StackPanel>
</StackPanel>
</SplitView.Pane>
<Frame x:Name="myFrame" />
</SplitView>
</Page>
Mainpage.xaml.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
namespace App1
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
myFrame.Navigate(typeof(Page1));
}
private void MenuButton1_Click(object sender, RoutedEventArgs e)
{
myFrame.Navigate(typeof(Page2));
}
private void HamburgerButton_Click(object sender, RoutedEventArgs e)
{
MySplitView.IsPaneOpen = !MySplitView.IsPaneOpen;
}
private void MenuButton2_Click(object sender, RoutedEventArgs e)
{
myFrame.Navigate(typeof(Page1)); //Home
}
private void MenuButton3_Click(object sender, RoutedEventArgs e)
{
//set image source at page2.myImagePage2
// ??
}
}
}
Page2.xaml
<Page
x:Class="App1.Page2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="#FFE03535">
<Image x:Name="myImagePage2" HorizontalAlignment="Left" Height="116" Margin="81,112,0,0" VerticalAlignment="Top" Width="175" Source="Assets/LockScreenLogo.png"/>
</Grid>
</Page>
我想将 Page2.myImagePage2 中的 ImageSource
从 MenuButton3_Click
如何访问 page2
中的函数?
该函数设置 Page2
上的 Visibilty
个项目。
我可以访问该功能并且项目变得不可见吗?
您可以使用 Page2
(Page2.xaml.cs
) 的代码隐藏来创建一个 public
方法来修改可见性(如 public void HideImage()
或 public void ChangeImageSource()
).
现在要在 Click
处理程序中获取当前页面,请使用 Frame.Content
属性:
private void MenuButton3_Click(object sender, RoutedEventArgs e)
{
var page = myFrame.Content as Page2;
if ( page != null )
{
//do something like calling your custom public method
//page.HideImage();
}
}