WinRt PasswordBox show button "Show password" - winrt-xaml

I'm developing an app for windows store and using PasswordBox in it. When I enter symbols in empty box - button "Show password" is showing. But when I edit value or copy symbols into passwordbox - there is no button.
Xaml:
<ScrollViewer Margin="10,15,20,15">
<Grid Margin="35,35,150,35" Visibility="Collapsed">
<Grid.RowDefinitions>
...
<RowDefinition Height="Auto"/>
...
</Grid.RowDefinitions>
...
<PasswordBox x:Name="pxPass" IsPasswordRevealButtonEnabled ="True" Grid.Row="6"/>
...
</Grid>
Code:
private void btnTapped(object sender, TappedRoutedEventArgs e)
{
pxPass.Focus(FocusState.Programmatic);
pxPass.Password = 'string';
}`
What can I do in this in this case?

But when I edit value or copy symbols into passwordbox - there is no
button.
Of course that is possible, the visibility of the password reveal button is determined by many things, not only the value of the IsPasswordRevealButtonEnabled property.
The value of this property is not the only factor that determines whether a password reveal button is visible to the user in UI. Other factors include whether the control is displayed above a minimum width, whether the PasswordBox has focus, and whether the text entry field contains at least one character.
Source : https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.passwordbox.ispasswordrevealbuttonenabled

Related

Add a disabled/ non-selectable separator in a bound ComboBox

I have a ComboBox and I want to add a separator which is disabled, non-selectable.
Standard functions such as add, edit, delete should be selectable under the separator.
The items containing an image and text should be displayed above the separator.
<ComboBox Name="cmbTest">
<!--These items should be loaded by code or ViewModel.-->
<ComboBoxItem >Item1</ComboBoxItem>
<ComboBoxItem >Item2</ComboBoxItem>
<ComboBoxItem >Item3</ComboBoxItem>
<!--Separator which is disabled.-->
<ComboBoxItem IsEnabled="False" >
<NavigationViewItemSeparator BorderThickness="1"></NavigationViewItemSeparator>
</ComboBoxItem>
<!--Menu below the separator.-->
<ComboBoxItem x:Name="cmbiNewApplication">Neu</ComboBoxItem>
<ComboBoxItem x:Name="cmbiEdit">Bearbeiten</ComboBoxItem>
<ComboBoxItem x:Name="cmbiDelete">Löschen</ComboBoxItem>
<ComboBoxItem x:Name="cmbiImportApplication">Import</ComboBoxItem>
<ComboBoxItem x:Name="cmbiExportApplication" >Export</ComboBoxItem>
</ComboBox>
Currently, my ComboBox is tied to a ViewModel and I've created a TemplateSelector on advice. Unfortunately, the ComboBoxItem in the template doesn't seem to be the generated ComboBoxItem itself, so the IsEnabled property has no effect.
<ComboBox x:Name="cmbApplication"
CornerRadius="3"
Width="300"
ItemsSource="{x:Bind AppProcessMainViewModel.AppProcesses}"
Tapped="cmbApplication_Tapped" >
<ComboBox.ItemTemplateSelector>
<local:MenuDataTemplateSelector>
<local:MenuDataTemplateSelector.DefaultTemplate>
<DataTemplate x:DataType="local:AppProcess" >
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Horizontal" Opacity="{x:Bind BoolToOpacity(Activated), Mode=OneWay}">
<TextBlock Text="{x:Bind Description, Mode=OneWay}"></TextBlock>
</StackPanel>
</StackPanel>
</DataTemplate>
</local:MenuDataTemplateSelector.DefaultTemplate>
<local:MenuDataTemplateSelector.MenuTemplate>
<DataTemplate x:DataType="local:AppProcess">
<ComboBoxItem IsEnabled="False" Height="22" >
<NavigationViewItemSeparator BorderThickness="1"></NavigationViewItemSeparator>
</ComboBoxItem>
</DataTemplate>
</local:MenuDataTemplateSelector.MenuTemplate>
</local:MenuDataTemplateSelector>
</ComboBox.ItemTemplateSelector>
</ComboBox>
My consideration was that I set the IsEnabled property of the item in the Tapped event of the combo box.
Unfortunately, I really can't figure out how to get the property of the ComboBoxItem by index.
How can I set the property?
Is this really the best approach (TemplateSelector and setting the property in the Tapped event)?
I've already read a lot about this and unfortunately there seems to be a lot missing in WinUI 3 in contrast to UWP/WPF that make things much easier.
I'm trying to get the item via the index and cast it, but there seems to be another problem, maybe because of the ViewModel?
Something like...
//Error
auto cb = cmbApplication().Items().GetAt(1).as<winrt::Microsoft::UI::Xaml::Controls::ComboBoxItem>();
I came across this site of the MS documentation (Find DataTemplate Generated Elements) and just tried it out, which works wonderfully... happy new year!
auto item = cmbApplication().ItemContainerGenerator().ContainerFromItem(cmbApplication().Items().GetAt(3));
item.as< winrt::Microsoft::UI::Xaml::Controls::ComboBoxItem>().IsEnabled(false);

Listbox keeps repeating first items

I have a simple listbox that loads items (in my test case 135).
I logged all the ID's of the items that are loaded, and they all have a unique ID. The listbox datatemplate is a usercontrol, so in the usercontrol I also logged the ID's to see which ones are loaded.
Now is where it starts going wrong, it only loads about the first 10 items (I think whatever is initially visible), and then keeps repeating those first items over and over again. So instead of 135 unique objects, I have 135 objects that are one of the first 10 or so loaded.
You can see the logging here (there are a lot more ID's not visible):
After the User Control ID's line, that's the only ID's it loads and keeps looping those 10 ID's until there are 135 items in the listbox.
This is the full page code
<Style x:Key="ListBoxItemStyle1" TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border x:Name="LayoutRoot" BorderThickness="3">
<ContentControl x:Name="ContentContainer"
VerticalContentAlignment="Top"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Foreground="{TemplateBinding Foreground}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Page.Resources>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<SearchBox x:Name="sbSearch" QuerySubmitted="sbSearch_QuerySubmitted" Margin="12,12,12,0"></SearchBox>
<ListBox x:Name="lbResults" Grid.Row="1" ItemContainerStyle="{StaticResource ListBoxItemStyle1}" Background="{x:Null}">
<ListBox.ItemTemplate>
<DataTemplate>
<userControls:WantlistItem Tag="{Binding}"></userControls:WantlistItem>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Grid>
What am I doing wrong?
Edit1: Loading of listbox in main page
private void Page_Loaded(object sender, RoutedEventArgs e)
{
if(Variables.WantsAll == null) Helpers.GetWantList();
foreach (var v in Variables.WantsAll)
{
Debug.WriteLine(v.id);
}
Debug.WriteLine("--- USER CONTROL ID's ---");
lbResults.ItemsSource = Variables.WantsAll;
}
In the UserControl Page_Loaded I'm logging them as well.
In this screenshot you can see I scrolled down, and it starts repeating the same items again (sometimes it messes up, as you can see the first item is not correctly repeated, it's a different one).
Note that in front of the names I added the ID's it prints out, you can see it's repeating the same ID's (for example the green album: 1301162), even tho in the list I set as ItemsSource it only exists once (all items are unique).
The comment provided by Jay Zuo - MSFT provided the solution, the answer in this thread solved my problem exactly.

Windows 10 Universal app flyout, how to remove scrollbars?

I've got a Flyout view with a TextBlock in it. The text block has more than one line's amount of text and I'd like it to wrap to the next line like it usually does, but when used in a Flyout it scrolls off the screen... How do you disable the scroll view in a Flyout?
Flyout XAML:
...
<AppBarButton.Flyout>
<Flyout Placement="Full">
<local:MyView/>
</Flyout>
</AppBarButton.Flyout>
...
My View XAML:
<UserControl ...>
<Grid>
...
<TextBlock Text="Loading..." Style="{ThemeResource SubtitleTextBlockStyle}" Margin="10,0,10,20" Grid.Row="1" TextWrapping="Wrap"/>
</Grid>
</UserControl>
It comes out like this:
To set properties of Flyout like width or scrollbar's visibility, we need to customize the style of FlyoutPresenter. Here is how I do it:
<Flyout Placement="Full" >
<Flyout.FlyoutPresenterStyle>
<Style TargetType="FlyoutPresenter">
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"></Setter>
</Style>
</Flyout.FlyoutPresenterStyle>
<Grid>
<TextBlock Text="This is an informational flyout. Click outside to dismiss.xxxjfdalisfsadpfuaspdfoia" Grid.Row="1" TextWrapping="Wrap"/>
</Grid>
</Flyout>
Directly copy the into your Flyout element will meet your requirement.
You can
1) make a maxwidth to your flyout
or
2) try this :
<Flyout Placement="full" >
<Grid ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
........
</Grid>
</Flyout>
best of luck !

WinRT: How do I set the hover over affect for a specific GridIViewtem?

I have a list of items bound to a GridView. The list contains multiple types of data. I use an ItemTemplateSelector to apply a DataTemplate to the different data types so they each have a unique look and feel.
I'm at a loss for how to remove the hover over effect of the GridViewItem in the DataTemplate for SubClass1 without DataTriggers.
public class Base
{
public string Name {get;set;}
}
public class SubClass1 : Base
{
}
public class SubClass2 : Base
{
}
public PageViewModel : ViewModelBase
{
public List<Base> ListOfBases {get;set;}
}
<GridView
x:Name="baseGridView"
ItemsSource="{Binding ListOfBases}"
ItemTemplateSelector="{StaticResource itemsTemplateSelector}"
SelectionMode="Multiple"
IsSwipeEnabled="false"
IsItemClickEnabled="True"
>
<DataTemplate x:Key="SubClass1Template">
<Grid Margin="0" Width="346" VerticalAlignment="Stretch" >
<TextBlock Grid.Column="0" Text="{Binding Name}" />
</Grid>
</DataTemplate>
You will need to edit the VisualState styles of the GridViewItem. To do this right click on the GridView within within VisualStudio or Blend. Do this within the Design view or the Document outline. Select Edit Additional Template -> Edit Generated Item Container (ItemContainerStyle) -> Edit a Copy
If you want to remove it completely, the remove the elements within the PointerOver state
<VisualState x:Name="PointerOver"/>
You can use this to make any changes to it as well. Maybe you do not like the default hover color, but like another, here is where you would make those changes.
UPDATE Based on comment
To only have the hover style for a certain class, set the Visibility of the controls used for the hover style (eg: a border) to bind directly to the class. Then a ValueConverter would return Visible or Collapsed based on the type of the class

Silverlight control InitializeComponent freezes application

I have a control that I create hundreds of times during the application.
I have noticed that my app freezes because in the Initializecomponent function,
there is
System.Windows.Application.LoadComponent(this, new System.Uri("/fa;component/Controls/Common/Popup/PopupItem.xaml", System.UriKind.Relative));
if I comment this out, the application runs smoothly (of course without the control rendered).
How can I avoid/increase performance so the XAML won't be loaded each time, but somehow to recycle the control??
for (int i = 5; i < colValues.Count; i++)
{
if (colValues[i].Count == "1")
continue;
PopupItem pi = new PopupItem(colValues[i], false, this, FilterCategorySearch.PopupContent);
FilterCategorySearch.PopupContent.spItemsContainer.Children.Add(pi);
}
and the XAML is
<UserControl x:Class="FacetedSearch.Controls.Common.Popup.PopupItem"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:FacetedSearch.Controls.Common"
mc:Ignorable="d">
<UserControl.Resources>
<SolidColorBrush x:Key="TextNormalBrush" Color="#FF656565"/>
<SolidColorBrush x:Key="TextHoverBrush" Color="#FFA39F9F"/>
</UserControl.Resources>
<StackPanel MouseEnter="LayoutRoot_MouseEnter" MouseLeave="LayoutRoot_MouseLeave" Orientation="Horizontal" Margin="0,4,0,0">
<local:CTLCheckBox x:Name="cbFilter" MouseLeftButtonUp="cbFilter_MouseLeftButtonUp" Cursor="Hand" Height="14" Width="10" Margin="4,0" />
<TextBlock x:Name="tbFilterName" Foreground="{StaticResource TextNormalBrush}" MouseLeftButtonUp="tbFilterName_MouseLeftButtonUp" TextWrapping="Wrap" FontFamily="Arial" Margin="0,0,4,0" Cursor="Hand"/>
<TextBlock x:Name="tbFilterCount" TextWrapping="Wrap" Foreground="{StaticResource TextNormalBrush}" FontFamily="Arial"/>
</StackPanel>
thanks
The xaml for UserControls is parsed by Silverlight for every new instance of the UserControl. This means that if you add 100 instances of the same UserControl, the xaml will be read, parsed, instantiated as objects then visual objects 100 times.
You have 2 possibilities:
Access your UserControl from another location by referencing it from within a DataTemplate (used by means of, say, a ContentControl)
Rewrite your UserControl to be a "real" control (i.e. a sublass of Control or ContentControl)

Resources