gpt4 book ai didi

xaml - UWP 中的 GroupBox 控件?

转载 作者:行者123 更新时间:2023-12-02 12:10:29 25 4
gpt4 key购买 nike

熟悉 UWP。我正在开发一个用于模拟电路的应用程序。有一个经典的视觉控件称为Frame,后来在WPF中称为GroupBox。UWP 中似乎没有此控件。UWP.Toolkit 库中有一个名为 HeaderedContentControl 的控件,但看起来不一样。似乎背景和边框属性不起作用..

目前我的代码是:

  <controls:HeaderedContentControl Margin="5" 
BorderBrush="Black" BorderThickness="1"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch">
<controls:HeaderedContentControl.Header>
<Border BorderBrush="Black" BorderThickness="1">
<Border.RenderTransform>
<TranslateTransform Y="-10"/>
</Border.RenderTransform>
<TextBlock Text="Resistor Value"/>
</Border>
</controls:HeaderedContentControl.Header>

<local:ComponentValueBox Unit="Ohm" HorizontalAlignment="Left"
Value="{x:Bind resistorValue, Mode=TwoWay}"
ValueChanged="changeR"/>

</controls:HeaderedContentControl>

我(在弹出窗口中)看到的是: My Resistor Parameters Flyout

不太像 GroupBox 控件..我希望看到如下内容:

enter image description here

我应该做什么?

最佳答案

UWP 与 WPF 不同。 UWP基于Windows运行时,WPF基于.NET Framework。它们都使用 XAML 来布局 UI 元素,但它们具有不同的 XAML 渲染引擎。你不可能认为 MS 放弃了旧的经典控件。他们完全在不同的平台上。我们将“UWP”称为 Unversal Windows Platform 。目前,您还找不到这样的“GroupBox”,但这是一个新平台,将来您也许能够看到这样的控件。一切皆有可能。

对于您的要求,就像@Muzib所说,您完全可以制作自定义控件来满足您的要求。我使用 UserControl TextBlock Border ContentControl 制作了这样一个“GroupBox”供您引用。

请参阅我的以下代码示例:

<UserControl
x:Class="AppGroupBox.GroupBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:AppGroupBox"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">

<Grid>
<TextBlock x:Name="HeaderTitle" Text="Header" Margin="7 0 0 0" LayoutUpdated="HeaderTitle_LayoutUpdated"></TextBlock>
<Border BorderBrush="Black" x:Name="border" BorderThickness="0 2 0 0" Margin="100 10 3 3" CornerRadius="0 5 0 0"></Border>
<Border BorderBrush="Black" BorderThickness="2 0 2 2" Margin="3 10 3 3" CornerRadius="5">
<ContentControl x:Name="Content" Margin="10 10 10 10">
</ContentControl>
</Border>
</Grid>

public sealed partial class GroupBox : UserControl
{
public GroupBox()
{
this.InitializeComponent();
}



public string Header
{
get { return (string)GetValue(HeaderProperty); }
set { SetValue(HeaderProperty, value); }
}

// Using a DependencyProperty as the backing store for Header. This enables animation, styling, binding, etc...
public static readonly DependencyProperty HeaderProperty =
DependencyProperty.Register("Header", typeof(string), typeof(GroupBox), new PropertyMetadata("Your Header", HeaderPropertyChangedCallback));

public static void HeaderPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (e.NewValue != e.OldValue)
{
(d as GroupBox).HeaderTitle.Text = e.NewValue?.ToString();
//(d as GroupBox).border.Margin = new Thickness((d as GroupBox).HeaderTitle.ActualWidth, 10, 3, 3);
}
}

public object CustomContent
{
get { return (object)GetValue(CustomContentProperty); }
set { SetValue(CustomContentProperty, value); }
}

// Using a DependencyProperty as the backing store for Content. This enables animation, styling, binding, etc...
public static readonly DependencyProperty CustomContentProperty =
DependencyProperty.Register("CustomContent", typeof(object), typeof(GroupBox), new PropertyMetadata(null,PropertyChangedCallback));

public static void PropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (e.NewValue != e.OldValue)
{
(d as GroupBox).Content.Content = e.NewValue;
}
}

private void HeaderTitle_LayoutUpdated(object sender, object e)
{
border.Margin = new Thickness(HeaderTitle.ActualWidth+10,10,3,3);
}
}
<local:GroupBox Header="My GroupBox" Height="300" Width="500">
<local:GroupBox.CustomContent>
<StackPanel>
<RadioButton Content="r1"></RadioButton>
<TextBox></TextBox>
</StackPanel>
</local:GroupBox.CustomContent>
</local:GroupBox>

enter image description here

关于xaml - UWP 中的 GroupBox 控件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51546880/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com