我想在WinUI-3中更改进度条的ProgressBarTrackHeight的高度。我不知道如何做,请用代码示例帮助我。
<ProgressBar Width="130" Value="30" />
字符串x1c 0d1x的数据
ih99xse11#
在GitHub repo中有一个关于这个的问题。作为一种解决方法,在问题得到解决之前,您可以创建一个自定义的ProgressBar:
ProgressBar
public class CustomProgressBar : ProgressBar { private long _heightPropertyChangedCallBackToken; public CustomProgressBar() : base() { Loaded += OnLoaded; Unloaded += OnUnloaded; } private void OnLoaded(object sender, RoutedEventArgs e) { _heightPropertyChangedCallBackToken = RegisterPropertyChangedCallback(HeightProperty, OnHeightPropertyChanged); ApplyHeight(); } private void OnUnloaded(object sender, RoutedEventArgs e) { UnregisterPropertyChangedCallback(HeightProperty, _heightPropertyChangedCallBackToken); } private void ApplyHeight() { foreach (FrameworkElement element in this.FindDescendants() .OfType<FrameworkElement>() .Where(x => x is Grid or Rectangle)) { element.Height = Height; } } private void OnHeightPropertyChanged(DependencyObject sender, DependencyProperty dp) { ApplyHeight(); } }
字符串现在Height属性应该可以工作了:
Height
<local:CustomProgressBar Height="50" Width="130" Value="30" />
型请注意,FindDescendants来自CommunityToolkit.WinUI.Extensions NuGet包。
FindDescendants
更新
在GitHub repo中,针对您不会动态更改Height的情况,建议了一个更好的选择。您只需设置MinHeight,而不是创建自定义ProgressBar:
MinHeight
<Grid> <Grid.Resources> <x:Double x:Key="ProgressBarTrackHeight">50</x:Double> </Grid.Resources> <ProgressBar MinHeight="{StaticResource ProgressBarTrackHeight}" Maximum="100" Value="70" /> </Grid>
型
1条答案
按热度按时间ih99xse11#
在GitHub repo中有一个关于这个的问题。
作为一种解决方法,在问题得到解决之前,您可以创建一个自定义的
ProgressBar
:字符串
现在
Height
属性应该可以工作了:型
请注意,
FindDescendants
来自CommunityToolkit.WinUI.Extensions NuGet包。更新
在GitHub repo中,针对您不会动态更改
Height
的情况,建议了一个更好的选择。您只需设置MinHeight
,而不是创建自定义ProgressBar
:型