当主题在运行时更改时,ProgressRing 不显示
ProgressRing not showing when Theme changed in runtime
我正在开发 UWP 应用程序。我使用 ProgressRing 如下代码:
<ListViewItem Template="{ThemeResource SeetingsListItemContentThemeStyle}"
BorderBrush="{ThemeResource SettingsListItemBorderThemeColor}"
BorderThickness="0,0,0,1"
AutomationProperties.SizeOfSet="0"
AutomationProperties.Name="{Binding SettingsAutomationText, Mode=OneWay}">
<ProgressRing VerticalAlignment="Center"
Margin="18, 0, 0, 14"
Height="21"
Width="21"
IsActive="True"
Foreground="Red"
Visibility="Visible"/>
</ListViewItem>
“SeetingsListItemContentThemeStyle”如下:
浅色主题:
<ControlTemplate x:Key="SeetingsListItemContentThemeStyle" TargetType="ListViewItem">
<ListViewItemPresenter x:Name="Root"
CheckBrush="{ThemeResource ListViewItemCheckBrush}"
ContentMargin="{TemplateBinding Padding}"
CheckBoxBrush="{ThemeResource ListViewItemCheckBoxBrush}"
CheckMode="{ThemeResource ListViewItemCheckMode}"
FocusBorderBrush="{ThemeResource ListViewItemFocusBorderBrush}"
FocusSecondaryBorderBrush="{ThemeResource ListViewItemFocusSecondaryBorderBrush}"
HorizontalContentAlignment="Left"
Control.IsTemplateFocusTarget="False"
PressedBackground="#12000000"
PlaceholderBackground="{ThemeResource ListViewItemPlaceholderBackground}"
PointerOverBackground="#08000000"
SelectionCheckMarkVisualEnabled="{ThemeResource ListViewItemSelectionCheckMarkVisualEnabled}"
SelectedPressedBackground="#12000000"
SelectedPointerOverBackground="#08000000"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}">
</ListViewItemPresenter>
</ControlTemplate>
深色主题:
<ControlTemplate x:Key="SeetingsListItemContentThemeStyle" TargetType="ListViewItem">
<ListViewItemPresenter x:Name="Root"
CheckBrush="{ThemeResource ListViewItemCheckBrush}"
ContentMargin="{TemplateBinding Padding}"
CheckBoxBrush="{ThemeResource ListViewItemCheckBoxBrush}"
CheckMode="{ThemeResource ListViewItemCheckMode}"
FocusBorderBrush="{ThemeResource ListViewItemFocusBorderBrush}"
FocusSecondaryBorderBrush="{ThemeResource ListViewItemFocusSecondaryBorderBrush}"
HorizontalContentAlignment="Left"
Control.IsTemplateFocusTarget="False"
PressedBackground="#12ffffff"
PlaceholderBackground="{ThemeResource ListViewItemPlaceholderBackground}"
PointerOverBackground="#08ffffff"
SelectionCheckMarkVisualEnabled="{ThemeResource ListViewItemSelectionCheckMarkVisualEnabled}"
SelectedPressedBackground="#12ffffff"
SelectedPointerOverBackground="#08ffffff"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}">
</ListViewItemPresenter>
</ControlTemplate>
进度环在父页面加载时正确显示。但是当我从系统更改主题时它没有显示。出现此问题后,Progress Ring 不会显示 Light-Dark 这两个主题。如果我返回其他页面并再次返回此页面,这次进度环会正确显示。
任何人都可以帮助我在应用运行时更改主题后正确使用进度环吗?
ProgressRing not showing when Theme changed in runtime
我认为问题是当您通过更新当前系统主题更改 ListViewItem 的 ControlTemplate 时,ProgressRing
环形动画被破坏了。对于这种情况,您可以在主题更改后重新加载当前页面以重建此动画。
private void Button_Click(object sender, RoutedEventArgs e)
{
Reload();
}
public bool Reload() { return Reload(null); }
private bool Reload(object param)
{
Type type = this.Frame.CurrentSourcePageType;
if (this.Frame.BackStack.Any())
{
type = this.Frame.BackStack.Last().SourcePageType;
param = this.Frame.BackStack.Last().Parameter;
}
try { return this.Frame.Navigate(type, param); }
finally { this.Frame.BackStack.Remove(this.Frame.BackStack.Last()); }
}
用法
public MainPage()
{
this.InitializeComponent();
var Listener = new ThemeListener();
Listener.ThemeChanged += Listener_ThemeChanged;
}
private void Listener_ThemeChanged(ThemeListener sender)
{
Reload();
}
我正在开发 UWP 应用程序。我使用 ProgressRing 如下代码:
<ListViewItem Template="{ThemeResource SeetingsListItemContentThemeStyle}"
BorderBrush="{ThemeResource SettingsListItemBorderThemeColor}"
BorderThickness="0,0,0,1"
AutomationProperties.SizeOfSet="0"
AutomationProperties.Name="{Binding SettingsAutomationText, Mode=OneWay}">
<ProgressRing VerticalAlignment="Center"
Margin="18, 0, 0, 14"
Height="21"
Width="21"
IsActive="True"
Foreground="Red"
Visibility="Visible"/>
</ListViewItem>
“SeetingsListItemContentThemeStyle”如下:
浅色主题:
<ControlTemplate x:Key="SeetingsListItemContentThemeStyle" TargetType="ListViewItem">
<ListViewItemPresenter x:Name="Root"
CheckBrush="{ThemeResource ListViewItemCheckBrush}"
ContentMargin="{TemplateBinding Padding}"
CheckBoxBrush="{ThemeResource ListViewItemCheckBoxBrush}"
CheckMode="{ThemeResource ListViewItemCheckMode}"
FocusBorderBrush="{ThemeResource ListViewItemFocusBorderBrush}"
FocusSecondaryBorderBrush="{ThemeResource ListViewItemFocusSecondaryBorderBrush}"
HorizontalContentAlignment="Left"
Control.IsTemplateFocusTarget="False"
PressedBackground="#12000000"
PlaceholderBackground="{ThemeResource ListViewItemPlaceholderBackground}"
PointerOverBackground="#08000000"
SelectionCheckMarkVisualEnabled="{ThemeResource ListViewItemSelectionCheckMarkVisualEnabled}"
SelectedPressedBackground="#12000000"
SelectedPointerOverBackground="#08000000"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}">
</ListViewItemPresenter>
</ControlTemplate>
深色主题:
<ControlTemplate x:Key="SeetingsListItemContentThemeStyle" TargetType="ListViewItem">
<ListViewItemPresenter x:Name="Root"
CheckBrush="{ThemeResource ListViewItemCheckBrush}"
ContentMargin="{TemplateBinding Padding}"
CheckBoxBrush="{ThemeResource ListViewItemCheckBoxBrush}"
CheckMode="{ThemeResource ListViewItemCheckMode}"
FocusBorderBrush="{ThemeResource ListViewItemFocusBorderBrush}"
FocusSecondaryBorderBrush="{ThemeResource ListViewItemFocusSecondaryBorderBrush}"
HorizontalContentAlignment="Left"
Control.IsTemplateFocusTarget="False"
PressedBackground="#12ffffff"
PlaceholderBackground="{ThemeResource ListViewItemPlaceholderBackground}"
PointerOverBackground="#08ffffff"
SelectionCheckMarkVisualEnabled="{ThemeResource ListViewItemSelectionCheckMarkVisualEnabled}"
SelectedPressedBackground="#12ffffff"
SelectedPointerOverBackground="#08ffffff"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}">
</ListViewItemPresenter>
</ControlTemplate>
进度环在父页面加载时正确显示。但是当我从系统更改主题时它没有显示。出现此问题后,Progress Ring 不会显示 Light-Dark 这两个主题。如果我返回其他页面并再次返回此页面,这次进度环会正确显示。
任何人都可以帮助我在应用运行时更改主题后正确使用进度环吗?
ProgressRing not showing when Theme changed in runtime
我认为问题是当您通过更新当前系统主题更改 ListViewItem 的 ControlTemplate 时,ProgressRing
环形动画被破坏了。对于这种情况,您可以在主题更改后重新加载当前页面以重建此动画。
private void Button_Click(object sender, RoutedEventArgs e)
{
Reload();
}
public bool Reload() { return Reload(null); }
private bool Reload(object param)
{
Type type = this.Frame.CurrentSourcePageType;
if (this.Frame.BackStack.Any())
{
type = this.Frame.BackStack.Last().SourcePageType;
param = this.Frame.BackStack.Last().Parameter;
}
try { return this.Frame.Navigate(type, param); }
finally { this.Frame.BackStack.Remove(this.Frame.BackStack.Last()); }
}
用法
public MainPage()
{
this.InitializeComponent();
var Listener = new ThemeListener();
Listener.ThemeChanged += Listener_ThemeChanged;
}
private void Listener_ThemeChanged(ThemeListener sender)
{
Reload();
}