New UI (not wired up)

This commit is contained in:
2026-09-22 15:23:39 +03:00 Unverified
parent 8ab8dde837
commit 5cb8eee38c
14 changed files with 426 additions and 54 deletions
@@ -10,6 +10,7 @@
xmlns:w="using:WinWARP.Core.ViewModels.Wrappers"
xmlns:conv="using:WinWARP.Ui.Converters"
xmlns:h="using:WinWARP.Ui.Helpers"
xmlns:u="using:WinUI3Localizer"
Height="64" Width="300"
mc:Ignorable="d">
@@ -23,17 +24,30 @@
<StackPanel>
</StackPanel>
</DataTemplate>
<conv:BoolToVisibilityConverter x:Key="BoolToVisConverter" />
</UserControl.Resources>
<UserControl.ContextFlyout>
<MenuFlyout x:Name="ServerListFlyout">
<MenuFlyoutItem Text="Option 1"/>
<MenuFlyoutItem Text="Option 2"/>
<MenuFlyout x:Name="ServerListFlyout" >
<MenuFlyoutItem Command="{x:Bind ServerData.EditNameCommand, Mode=OneWay}" u:Uids.Uid="{x:Bind GetUidForNameEditing(ServerData.IsNameEditing), Mode=OneWay}">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="{x:Bind GetGlyphForNameEditing(ServerData.IsNameEditing), Mode=OneWay}" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<ToggleMenuFlyoutItem u:Uids.Uid="ServerListElementMenuFlyoutIsDisabled" IsChecked="{x:Bind ServerData.IsDisabled, Mode=TwoWay}">
<ToggleMenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE7E8;" />
</ToggleMenuFlyoutItem.Icon>
</ToggleMenuFlyoutItem>
<MenuFlyoutSeparator/>
<MenuFlyoutItem u:Uids.Uid="ServerListElementMenuFlyoutDelete" Command="{x:Bind ServerData.DeleteCommand}">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xE74D;" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
</MenuFlyout>
</UserControl.ContextFlyout>
<Grid MaxHeight="64"
Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
CornerRadius="4">
<Grid MaxHeight="64" Background="{ThemeResource CardBackgroundFillColorDefaultBrush}" CornerRadius="4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="64"/>
<ColumnDefinition Width="*"/>
@@ -57,10 +71,11 @@
<Rectangle Grid.Column="1" Grid.Row="1" Fill="Beige"/>
<Rectangle Grid.Column="1" Grid.Row="2" Fill="Brown"/>-->
<StackPanel Grid.Column="1">
<TextBlock Text="{x:Bind Title(ServerData), Mode=OneWay}" Style="{StaticResource BodyTextBlockStyle}"/>
<TextBox Text="{x:Bind ServerData.Title, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" u:Uids.Uid="ServerListElementTitleTextBox" Style="{StaticResource BodyTextBlockStyle}" Visibility="{x:Bind ServerData.IsNameEditing, Converter={StaticResource BoolToVisConverter}, Mode=OneWay}"/>
<TextBlock Text="{x:Bind GetTitle(ServerData), Mode=OneWay}" Style="{StaticResource BodyTextBlockStyle}" Visibility="{x:Bind ServerData.IsNameEditing, Converter={StaticResource BoolToVisConverter}, ConverterParameter=True, Mode=OneWay}"/>
<TextBlock Text="{x:Bind ServerData.DefaultTitle, Mode=OneWay}" Style="{StaticResource CaptionTextBlockStyle}" Visibility="{x:Bind IsNotDefaultTitle(ServerData), Mode=OneWay}"/>
</StackPanel>
<Button Grid.Column="2" Height="24" Width="24" Padding="0" Margin="4" VerticalAlignment="Top" Click="MenuButton_Click">
<Button Grid.RowSpan="2" Grid.Column="2" Height="20" Width="20" Padding="0" Margin="4" VerticalAlignment="Bottom" Click="MenuButton_Click">
<FontIcon Glyph="&#xE712;" FontSize="10"/>
</Button>
<ItemsView Grid.Column="1" Grid.Row="1" ItemsSource="{x:Bind ServerData.Tags, Mode=OneWay}" VerticalAlignment="Center" SelectionMode="None">
@@ -27,7 +27,7 @@ public sealed partial class ServerListElement : UserControl
public static readonly DependencyProperty ServerDataProperty =
DependencyProperty.Register(nameof(ServerData), typeof(ServerItemViewModel),
typeof(ServerListElement), new PropertyMetadata(null));
typeof(ServerListElement), new PropertyMetadata(null, OnServerDataChanged));
public ServerItemViewModel ServerData
{
@@ -35,7 +35,7 @@ public sealed partial class ServerListElement : UserControl
set => SetValue(ServerDataProperty, value);
}
public string Title(ServerItemViewModel serverData) => string.IsNullOrEmpty(serverData?.Title) ? (string.IsNullOrEmpty(serverData?.DefaultTitle) ? string.Empty : serverData.DefaultTitle) : serverData.Title;
public string GetTitle(ServerItemViewModel serverData) => string.IsNullOrEmpty(serverData?.Title) ? (string.IsNullOrEmpty(serverData?.DefaultTitle) ? string.Empty : serverData.DefaultTitle) : serverData.Title;
public Visibility IsNotDefaultTitle(ServerItemViewModel serverData) => (!string.IsNullOrEmpty(serverData?.Title) && serverData?.Title != serverData?.DefaultTitle) ? Visibility.Visible : Visibility.Collapsed;
@@ -80,4 +80,28 @@ public sealed partial class ServerListElement : UserControl
ServerListFlyout.ShowAt(button, options);
}
}
private static void OnServerDataChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var control = (ServerListElement)d;
if (e.OldValue is ServerItemViewModel oldVM) oldVM.PropertyChanged -= control.OnServerItemPropertyChanged;
if (e.NewValue is ServerItemViewModel newVM) newVM.PropertyChanged += control.OnServerItemPropertyChanged;
}
private void OnServerItemPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(ServerItemViewModel.Title)) Bindings.Update();
}
private string GetUidForNameEditing(bool isNameEditing)
{
if (isNameEditing) return "ServerListElementMenuFlyoutSave";
else return "ServerListElementMenuFlyoutEdit";
}
private string GetGlyphForNameEditing(bool isNameEditing)
{
if (isNameEditing) return "\uE792";
else return "\uE70F";
}
}