Skip to content

Commit

Permalink
fix: Category selection is now working
Browse files Browse the repository at this point in the history
  • Loading branch information
jp-weber committed Mar 17, 2024
1 parent 4c8f38c commit 46674de
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
using Windows.Storage.Streams;
using Windows.Storage;
using UNOversal.Services.Serialization;
using CommunityToolkit.WinUI.Collections;




#if WINDOWS_UWP
Expand All @@ -37,9 +40,11 @@ public class ManageCategoriesContentDialogViewModel : ObservableRecipient, IDial
private FontIdentifikationModel _selectedIconItem;
private bool _canCreate;
private ISerializationService SerializationService { get; }
public AdvancedCollectionView ACVCollection { get; private set; }

public ObservableCollection<FontIdentifikationModel> IconSourceCollection { get; private set; } = new ObservableCollection<FontIdentifikationModel>();
public ObservableCollection<CategoryModel> TempGlobalCategories { get; private set; } = new ObservableCollection<CategoryModel>();
private FontIdentifikationModel _selectedComboBoxItem;
private string _label;

public ManageCategoriesContentDialogViewModel(ISerializationService serializationService)
Expand All @@ -64,6 +69,8 @@ public async Task InitializeAsync(IDialogParameters parameters)
IRandomAccessStreamWithContentType randomStream = await file.OpenReadAsync();
using StreamReader r = new StreamReader(randomStream.AsStreamForRead());
IconSourceCollection.AddRange(SerializationService.Deserialize<ObservableCollection<FontIdentifikationModel>>(await r.ReadToEndAsync()));
ACVCollection = new AdvancedCollectionView(IconSourceCollection, true);
ACVCollection.SortDescriptions.Add(new SortDescription("Name", SortDirection.Ascending));
TempGlobalCategories ??= new ObservableCollection<CategoryModel>();
for (int i = 0; i < DataService.Instance.GlobalCategories.Count; i++)
{
Expand Down Expand Up @@ -159,5 +166,9 @@ public bool CanCreate
get => _canCreate;
set => SetProperty(ref _canCreate, value);
}
public FontIdentifikationModel SelectedComboBoxItem
{
get => _selectedComboBoxItem;
set => SetProperty(ref _selectedComboBoxItem, value); }
}
}
2 changes: 1 addition & 1 deletion Project2FA/Project2FA.UWP/Project2FA.UWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<AssemblyName>Project2FA.UWP</AssemblyName>
<DefaultLanguage>en</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.22621.0</TargetPlatformVersion>
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.19041.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
</appcontrols:CardExpanderControl>

<ListView
x:Name="LV_Categories"
ItemContainerStyle="{StaticResource TwoFASelectionListViewItemStyle}"
ItemsSource="{x:Bind ViewModel.TempGlobalCategories, Mode=OneWay}">
<ListView.ItemTemplate>
Expand All @@ -117,13 +118,40 @@
FontSize="32"
Glyph="{x:Bind UnicodeIndex, Mode=OneWay, Converter={StaticResource FontIconUnicodeIndexToGlyphConverter}}"/>
<Button
x:Name="BTN_ShowIcons"
Margin="4,0,0,0"
Grid.Column="1"
CornerRadius="99"
Width="40"
Height="40">
Height="40"
Click="BTN_ShowIcons_Click">
<FontIcon FontSize="12" Glyph="&#xE70F;"/>
<Button.Flyout>
<FlyoutBase.AttachedFlyout>
<muxc:CommandBarFlyout
Placement="Right"
Opening="CommandBarFlyout_Opening">
<muxc:CommandBarFlyout.PrimaryCommands>
<AppBarElementContainer>
<ComboBox
x:Name="CB_CategoryModel"
BorderBrush="{ThemeResource SystemAccentColor}"
MinWidth="220"
VerticalAlignment="Center"
HorizontalAlignment="Stretch"
MinHeight="34"
SelectedValuePath="UnicodeIndex"
SelectedItem="{Binding DataContext.SelectedComboBoxItem, ElementName=Page,Mode=TwoWay}"
ItemTemplate="{StaticResource SymbolListTemplate}"
ItemsSource="{Binding DataContext.ACVCollection, ElementName=Page, Mode=OneWay}"
Loaded="CB_CategoryModel_Loaded"/>
</AppBarElementContainer>
<AppBarButton
Icon="Accept"
Click="AppBarButton_Click"/>
</muxc:CommandBarFlyout.PrimaryCommands>
</muxc:CommandBarFlyout>
</FlyoutBase.AttachedFlyout>
<!--<Button.Flyout>
<muxc:CommandBarFlyout Placement="Right">
<muxc:CommandBarFlyout.PrimaryCommands>
<AppBarElementContainer>
Expand All @@ -141,11 +169,11 @@
</ComboBox>
</AppBarElementContainer>
<AppBarButton

Icon="Accept" Click="AppBarButton_Click"/>
Icon="Accept"
Click="AppBarButton_Click"/>
</muxc:CommandBarFlyout.PrimaryCommands>
</muxc:CommandBarFlyout>
</Button.Flyout>
</Button.Flyout>-->
</Button>
<TextBox
TextChanged="TextBox_TextChanged"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Media;
using CommandBarFlyout = Microsoft.UI.Xaml.Controls.CommandBarFlyout;

namespace Project2FA.UWP.Views
{
public sealed partial class ManageCategoriesContentDialog : ContentDialog
{
public ManageCategoriesContentDialogViewModel ViewModel => DataContext as ManageCategoriesContentDialogViewModel;

private CommandBarFlyout _openedCommandBarFlyout;
public ManageCategoriesContentDialog()
{
this.InitializeComponent();
Expand Down Expand Up @@ -53,51 +56,46 @@ private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
ViewModel.DataChanged = true;
}

private void CB_CategoryModel_SelectionChanged(object sender, SelectionChangedEventArgs e)
private void CB_CategoryModel_Loaded(object sender, RoutedEventArgs e)
{
if ((FrameworkElement)sender is ComboBox cb)
{
if (cb.DataContext is CategoryModel model)
{
var newValue = (FontIdentifikationModel)cb.SelectedItem;
model.UnicodeIndex = newValue.UnicodeIndex.ToString();
model.UnicodeString = newValue.UnicodeString;
ViewModel.SelectedComboBoxItem = ViewModel.IconSourceCollection.Where(x => x.UnicodeIndex == Convert.ToUInt32(model.UnicodeIndex)).FirstOrDefault();
//cb.SelectedItem = ViewModel.IconSourceCollection.Where(x => x.UnicodeIndex == Convert.ToUInt32(model.UnicodeIndex)).FirstOrDefault();
}
}

}

private void CB_CategoryModel_Loaded(object sender, RoutedEventArgs e)
private void AppBarButton_Click(object sender, RoutedEventArgs e)
{
if ((FrameworkElement)sender is ComboBox cb)
//FindAndCloseFlyout(sender);
_openedCommandBarFlyout?.Hide();
if (ViewModel.SelectedComboBoxItem != null)
{
if (cb.DataContext is CategoryModel model)
if (sender is AppBarButton abtn && abtn.DataContext is CategoryModel model)
{
cb.SelectedItem = ViewModel.IconSourceCollection.Where(x => x.UnicodeIndex == Convert.ToUInt32(model.UnicodeIndex)).FirstOrDefault();
model.UnicodeIndex = ViewModel.SelectedComboBoxItem.UnicodeIndex.ToString();
model.UnicodeString = ViewModel.SelectedComboBoxItem.UnicodeString;
}
}
}

private void FindAndCloseFlyout(object sender)
private void BTN_ShowIcons_Click(object sender, RoutedEventArgs e)
{
var parent = Page ?? sender as DependencyObject;
while (parent != null)
if (sender is Button btn)
{
if (parent is FlyoutPresenter)
{
((parent as FlyoutPresenter).Parent as Popup).IsOpen = false;
break;
}
else
{
parent = VisualTreeHelper.GetParent(parent);
}
FlyoutBase.ShowAttachedFlyout(btn);
}
}

private void AppBarButton_Click(object sender, RoutedEventArgs e)
private void CommandBarFlyout_Opening(object sender, object e)
{
FindAndCloseFlyout(sender);
if (sender is Microsoft.UI.Xaml.Controls.CommandBarFlyout cmdf)
{
_openedCommandBarFlyout = cmdf;
}
}
}
}

0 comments on commit 46674de

Please sign in to comment.