小编Hen*_*nri的帖子

UWP C#中的ToggleSwitch

我有一个小问题.我正在尝试创建一个UWP C#应用程序,我正在项目中使用切换开关.如果我经常从软件切换ToggleSwitch的状态,则内存使用量会大大增加.为什么会这样?

ToggleSwitch表示使用绑定的布尔值.

我创建了示例代码:

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">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <ToggleSwitch Header="Test" HorizontalAlignment="Left" Margin="213,27,0,0" VerticalAlignment="Top" IsOn="{Binding Path=TestBool, Mode=TwoWay}"/>
    <CheckBox Content="Two-state CheckBox" Margin="108,162,0,806" IsChecked="{Binding Path=TestBool, Mode=TwoWay}"/>
    <Button Content="Start!" HorizontalAlignment="Left" Margin="69,58,0,0" VerticalAlignment="Top" Click="Button_Click"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)

C#:

using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using System.ComponentModel;
using System.Runtime.CompilerServices;

// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409

namespace App1
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// …
Run Code Online (Sandbox Code Playgroud)

c# xaml uwp

6
推荐指数
1
解决办法
871
查看次数

标签 统计

c# ×1

uwp ×1

xaml ×1