Togglebutton fixes

- move dot to the right in style
- cleanup code
- fix arrangement of content
This commit is contained in:
MyDrift 2024-10-26 15:25:33 +02:00
parent fd4d783a04
commit c0d6e0bbc7
4 changed files with 11 additions and 24 deletions

View File

@ -7,7 +7,7 @@
"Description": "Toggle between a list and a compact grid like view" "Description": "Toggle between a list and a compact grid like view"
}, },
"WPFSelectedFilter": { "WPFSelectedFilter": {
"Content": ["Show Selected", "Show All"], "Content": [ "Show All", "Show Selected"],
"Category": "____Actions", "Category": "____Actions",
"Type": "ToggleButton", "Type": "ToggleButton",
"Order": "2", "Order": "2",

View File

@ -194,29 +194,16 @@ function Invoke-WPFUIElements {
} }
"ToggleButton" { "ToggleButton" {
# Determine contentOn and contentOff based on the Content property
if ($entryInfo.Content -is [array]) {
# If Content is an array, use its elements
write-host "Content is an array"
write-host $entryInfo.Content
$contentOn = if ($entryInfo.Content.Count -ge 1) { $entryInfo.Content[0] } else { "" }
$contentOff = if ($entryInfo.Content.Count -ge 2) { $entryInfo.Content[1] } else { $contentOn }
} else {
# If Content is a single value, use it for both states
$contentOn = $entryInfo.Content
$contentOff = $entryInfo.Content
}
$toggleButton = New-Object Windows.Controls.Primitives.ToggleButton $toggleButton = New-Object Windows.Controls.Primitives.ToggleButton
$toggleButton.Name = $entryInfo.Name $toggleButton.Name = $entryInfo.Name
$toggleButton.Content = $contentOff $toggleButton.Content = $entryInfo.Content[1]
$toggleButton.ToolTip = $entryInfo.Description $toggleButton.ToolTip = $entryInfo.Description
$toggleButton.HorizontalAlignment = "Left" $toggleButton.HorizontalAlignment = "Left"
$toggleButton.Style = $ToggleButtonStyle $toggleButton.Style = $ToggleButtonStyle
$toggleButton.Tag = @{ $toggleButton.Tag = @{
contentOn = $contentOn contentOn = if ($entryInfo.Content.Count -ge 1) { $entryInfo.Content[0] } else { "" }
contentOff = $contentOff contentOff = if ($entryInfo.Content.Count -ge 2) { $entryInfo.Content[1] } else { $contentOn }
} }
$itemsControl.Items.Add($toggleButton) | Out-Null $itemsControl.Items.Add($toggleButton) | Out-Null

View File

@ -360,9 +360,9 @@
<Ellipse x:Name="ToggleDot" <Ellipse x:Name="ToggleDot"
Width="8" Height="8" Width="8" Height="8"
Fill="{DynamicResource ButtonForegroundColor}" Fill="{DynamicResource ButtonForegroundColor}"
HorizontalAlignment="Left" HorizontalAlignment="Right"
VerticalAlignment="Top" VerticalAlignment="Top"
Margin="5,3,0,0" /> Margin="0,3,5,0" />
<!-- Content Presenter --> <!-- Content Presenter -->
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Margin="10,2,10,2"/> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Margin="10,2,10,2"/>
@ -374,7 +374,7 @@
<ControlTemplate.Triggers> <ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True"> <Trigger Property="IsChecked" Value="True">
<Setter TargetName="ToggleDot" Property="VerticalAlignment" Value="Bottom"/> <Setter TargetName="ToggleDot" Property="VerticalAlignment" Value="Bottom"/>
<Setter TargetName="ToggleDot" Property="Margin" Value="5,0,0,3"/> <!-- Consistent bottom margin --> <Setter TargetName="ToggleDot" Property="Margin" Value="0,0,5,3"/> <!-- Consistent bottom margin on the right -->
</Trigger> </Trigger>
<Trigger Property="IsPressed" Value="True"> <Trigger Property="IsPressed" Value="True">