-
Notifications
You must be signed in to change notification settings - Fork 8
-
Can you explain how you did the search functionality , please . |
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment · 1 reply
-
The search box is a You can check the code implementation here:
|
<UserControl x:Class="Gavilya.UserControls.SearchItem" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |
xmlns:local="clr-namespace:Gavilya.UserControls" FontFamily="..\Fonts\#Montserrat" | |
mc:Ignorable="d" MouseLeftButtonUp="UserControl_MouseLeftButtonUp" | |
Height="45" d:DesignWidth="800"> | |
<Grid> | |
<Grid.ColumnDefinitions> | |
<ColumnDefinition Width="Auto"/> | |
<ColumnDefinition/> | |
</Grid.ColumnDefinitions> | |
<Image x:Name="GameImg" Width="80" Stretch="Fill"/> | |
<TextBlock x:Name="GameName" d:Text="Game Name" Foreground="#fff" FontSize="20" Margin="7,0,0,0" Grid.Column="1" VerticalAlignment="Center" FontWeight="Bold"/> | |
</Grid> | |
</UserControl> |
C#
Gavilya/Gavilya/UserControls/SearchItem.xaml.cs
Lines 35 to 93 in ec7d8a6
public partial class SearchItem : UserControl | |
{ | |
internal GameCard ParentGameCard { get; init; } | |
public SearchItem(GameCard parent) | |
{ | |
InitializeComponent(); | |
ParentGameCard = parent; // Define the parent element | |
InitUI(); // Load the UI | |
} | |
private void InitUI() | |
{ | |
try | |
{ | |
// Load the Image | |
if (ParentGameCard.GameInfo.IconFileLocation != string.Empty && ParentGameCard.GameInfo.IconFileLocation != null) // If a custom image is used | |
{ | |
var bitmap = new BitmapImage(); | |
var stream = File.OpenRead(ParentGameCard.GameInfo.IconFileLocation); | |
bitmap.BeginInit(); | |
bitmap.CacheOption = BitmapCacheOption.OnLoad; | |
bitmap.StreamSource = stream; | |
bitmap.DecodePixelWidth = 80; | |
bitmap.EndInit(); | |
stream.Close(); | |
stream.Dispose(); | |
bitmap.Freeze(); | |
GameImg.Source = bitmap; | |
} | |
else | |
{ | |
if (!ParentGameCard.GameInfo.IsUWP && !ParentGameCard.GameInfo.IsSteam) // If the game isn't UWP | |
{ | |
System.Drawing.Icon icon = System.Drawing.Icon.ExtractAssociatedIcon(ParentGameCard.GameInfo.FileLocation); | |
GameImg.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); // Show the image | |
} | |
} | |
// Set the Game name | |
GameName.Text = ParentGameCard.GameInfo.Name; | |
} | |
catch | |
{ | |
GameImg.Source = new BitmapImage(new Uri("pack://application:,,,/Gavilya;component/Assets/PC.png")); // Show the default image | |
} | |
} | |
public override string ToString() | |
{ | |
return ParentGameCard.GameInfo.Name; | |
} | |
internal void UserControl_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e) | |
{ | |
ParentGameCard.GameCardBorder_MouseLeftButtonUp(this, e); | |
} | |
} |
App.xaml
Lines 1143 to 1420 in ec7d8a6
<Style x:Key="ComboBoxEditableTextBox" TargetType="{x:Type TextBox}"> | |
<Setter Property="OverridesDefaultStyle" Value="true"/> | |
<Setter Property="AllowDrop" Value="true"/> | |
<Setter Property="MinWidth" Value="0"/> | |
<Setter Property="MinHeight" Value="0"/> | |
<Setter Property="FocusVisualStyle" Value="{x:Null}"/> | |
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/> | |
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/> | |
<Setter Property="VerticalAlignment" Value="Center"/> | |
<Setter Property="VerticalContentAlignment" Value="Center"/> | |
<Setter Property="Foreground" Value="#FFF"/> | |
<Setter Property="Template"> | |
<Setter.Value> | |
<ControlTemplate TargetType="{x:Type TextBox}"> | |
<ScrollViewer x:Name="PART_ContentHost" Background="Transparent" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/> | |
</ControlTemplate> | |
</Setter.Value> | |
</Setter> | |
</Style> | |
<LinearGradientBrush x:Key="ComboBox.Static.Background" EndPoint="0,1" StartPoint="0,0"> | |
<GradientStop Color="Transparent" Offset="0.0"/> | |
<GradientStop Color="Transparent" Offset="1.0"/> | |
</LinearGradientBrush> | |
<SolidColorBrush x:Key="ComboBox.Static.Border" Color="#6600FF"/> | |
<SolidColorBrush x:Key="ComboBox.Static.Glyph" Color="#6600FF"/> | |
<SolidColorBrush x:Key="ComboBox.Static.Editable.Background" Color="Transparent"/> | |
<SolidColorBrush x:Key="ComboBox.Static.Editable.Border" Color="#FF1E1E32"/> | |
<SolidColorBrush x:Key="ComboBox.Static.Editable.Button.Background" Color="Transparent"/> | |
<SolidColorBrush x:Key="ComboBox.Static.Editable.Button.Border" Color="Transparent"/> | |
<SolidColorBrush x:Key="TextBox.Static.Background" Color="#FF1E1E32"/> | |
<LinearGradientBrush x:Key="ComboBox.MouseOver.Background" EndPoint="0,1" StartPoint="0,0"> | |
<GradientStop Color="#6600FF" Offset="0.0"/> | |
<GradientStop Color="#6600FF" Offset="1.0"/> | |
</LinearGradientBrush> | |
<SolidColorBrush x:Key="ComboBox.MouseOver.Border" Color="#6600FF"/> | |
<SolidColorBrush x:Key="ComboBox.MouseOver.Glyph" Color="#fff"/> | |
<SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Background" Color="#FF1E1E32"/> | |
<SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Border" Color="#FF1E1E32"/> | |
<LinearGradientBrush x:Key="ComboBox.MouseOver.Editable.Button.Background" EndPoint="0,1" StartPoint="0,0"> | |
<GradientStop Color="#6600FF" Offset="0.0"/> | |
<GradientStop Color="#6600FF" Offset="1.0"/> | |
</LinearGradientBrush> | |
<SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Button.Border" Color="#6600FF"/> | |
<LinearGradientBrush x:Key="ComboBox.Pressed.Background" EndPoint="0,1" StartPoint="0,0"> | |
<GradientStop Color="#6600FF" Offset="0.0"/> | |
<GradientStop Color="#6600FF" Offset="1.0"/> | |
</LinearGradientBrush> | |
<SolidColorBrush x:Key="ComboBox.Pressed.Border" Color="#6600FF"/> | |
<SolidColorBrush x:Key="ComboBox.Pressed.Glyph" Color="#fff"/> | |
<SolidColorBrush x:Key="ComboBox.Pressed.Editable.Background" Color="Transparent"/> | |
<SolidColorBrush x:Key="ComboBox.Pressed.Editable.Border" Color="#6600FF"/> | |
<LinearGradientBrush x:Key="ComboBox.Pressed.Editable.Button.Background" EndPoint="0,1" StartPoint="0,0"> | |
<GradientStop Color="#6600FF" Offset="0.0"/> | |
<GradientStop Color="#6600FF" Offset="1.0"/> | |
</LinearGradientBrush> | |
<SolidColorBrush x:Key="ComboBox.Pressed.Editable.Button.Border" Color="#6600FF"/> | |
<SolidColorBrush x:Key="ComboBox.Disabled.Background" Color="Transparent"/> | |
<SolidColorBrush x:Key="ComboBox.Disabled.Border" Color="#FFD9D9D9"/> | |
<SolidColorBrush x:Key="ComboBox.Disabled.Glyph" Color="#FFBFBFBF"/> | |
<SolidColorBrush x:Key="ComboBox.Disabled.Editable.Background" Color="#FFFFFFFF"/> | |
<SolidColorBrush x:Key="ComboBox.Disabled.Editable.Border" Color="#FFBFBFBF"/> | |
<SolidColorBrush x:Key="ComboBox.Disabled.Editable.Button.Background" Color="Transparent"/> | |
<SolidColorBrush x:Key="ComboBox.Disabled.Editable.Button.Border" Color="Transparent"/> | |
<Style x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}"> | |
<Setter Property="OverridesDefaultStyle" Value="true"/> | |
<Setter Property="IsTabStop" Value="false"/> | |
<Setter Property="Focusable" Value="false"/> | |
<Setter Property="ClickMode" Value="Press"/> | |
<Setter Property="Template"> | |
<Setter.Value> | |
<ControlTemplate TargetType="{x:Type ToggleButton}"> | |
<Border x:Name="templateRoot" Background="{StaticResource ComboBox.Static.Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{StaticResource ComboBox.Static.Border}" CornerRadius="4" SnapsToDevicePixels="true"> | |
<Border x:Name="splitBorder" BorderThickness="1" BorderBrush="Transparent" HorizontalAlignment="Right" Margin="0" SnapsToDevicePixels="true" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"> | |
<Path x:Name="arrow" Data="F1 M 0,0 L 2.667,2.66665 L 5.3334,0 L 5.3334,-1.78168 L 2.6667,0.88501 L0,-1.78168 L0,0 Z" Fill="{StaticResource ComboBox.Static.Glyph}" HorizontalAlignment="Center" Margin="0" VerticalAlignment="Center"/> | |
</Border> | |
</Border> | |
<ControlTemplate.Triggers> | |
<MultiDataTrigger> | |
<MultiDataTrigger.Conditions> | |
<Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true"/> | |
<Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="false"/> | |
<Condition Binding="{Binding IsPressed, RelativeSource={RelativeSource Self}}" Value="false"/> | |
<Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="true"/> | |
</MultiDataTrigger.Conditions> | |
<Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Static.Editable.Background}"/> | |
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Static.Editable.Border}"/> | |
<Setter Property="Background" TargetName="splitBorder" Value="{StaticResource ComboBox.Static.Editable.Button.Background}"/> | |
<Setter Property="BorderBrush" TargetName="splitBorder" Value="{StaticResource ComboBox.Static.Editable.Button.Border}"/> | |
</MultiDataTrigger> | |
<Trigger Property="IsMouseOver" Value="true"> | |
<Setter Property="Fill" TargetName="arrow" Value="{StaticResource ComboBox.MouseOver.Glyph}"/> | |
</Trigger> | |
<MultiDataTrigger> | |
<MultiDataTrigger.Conditions> | |
<Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="true"/> | |
<Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="false"/> | |
</MultiDataTrigger.Conditions> | |
<Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.MouseOver.Background}"/> | |
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.MouseOver.Border}"/> | |
</MultiDataTrigger> | |
<MultiDataTrigger> | |
<MultiDataTrigger.Conditions> | |
<Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="true"/> | |
<Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true"/> | |
</MultiDataTrigger.Conditions> | |
<Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.MouseOver.Editable.Background}"/> | |
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.MouseOver.Editable.Border}"/> | |
<Setter Property="Background" TargetName="splitBorder" Value="{StaticResource ComboBox.MouseOver.Editable.Button.Background}"/> | |
<Setter Property="BorderBrush" TargetName="splitBorder" Value="{StaticResource ComboBox.MouseOver.Editable.Button.Border}"/> | |
</MultiDataTrigger> | |
<Trigger Property="IsPressed" Value="true"> | |
<Setter Property="Fill" TargetName="arrow" Value="{StaticResource ComboBox.Pressed.Glyph}"/> | |
</Trigger> | |
<MultiDataTrigger> | |
<MultiDataTrigger.Conditions> | |
<Condition Binding="{Binding IsPressed, RelativeSource={RelativeSource Self}}" Value="true"/> | |
<Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="false"/> | |
</MultiDataTrigger.Conditions> | |
<Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Pressed.Background}"/> | |
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Pressed.Border}"/> | |
</MultiDataTrigger> | |
<MultiDataTrigger> | |
<MultiDataTrigger.Conditions> | |
<Condition Binding="{Binding IsPressed, RelativeSource={RelativeSource Self}}" Value="true"/> | |
<Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true"/> | |
</MultiDataTrigger.Conditions> | |
<Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Pressed.Editable.Background}"/> | |
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Pressed.Editable.Border}"/> | |
<Setter Property="Background" TargetName="splitBorder" Value="{StaticResource ComboBox.Pressed.Editable.Button.Background}"/> | |
<Setter Property="BorderBrush" TargetName="splitBorder" Value="{StaticResource ComboBox.Pressed.Editable.Button.Border}"/> | |
</MultiDataTrigger> | |
<Trigger Property="IsEnabled" Value="false"> | |
<Setter Property="Fill" TargetName="arrow" Value="{StaticResource ComboBox.Disabled.Glyph}"/> | |
</Trigger> | |
<MultiDataTrigger> | |
<MultiDataTrigger.Conditions> | |
<Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="false"/> | |
<Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="false"/> | |
</MultiDataTrigger.Conditions> | |
<Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Disabled.Background}"/> | |
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Disabled.Border}"/> | |
</MultiDataTrigger> | |
<MultiDataTrigger> | |
<MultiDataTrigger.Conditions> | |
<Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="false"/> | |
<Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true"/> | |
</MultiDataTrigger.Conditions> | |
<Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Disabled.Editable.Background}"/> | |
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Disabled.Editable.Border}"/> | |
<Setter Property="Background" TargetName="splitBorder" Value="{StaticResource ComboBox.Disabled.Editable.Button.Background}"/> | |
<Setter Property="BorderBrush" TargetName="splitBorder" Value="{StaticResource ComboBox.Disabled.Editable.Button.Border}"/> | |
</MultiDataTrigger> | |
</ControlTemplate.Triggers> | |
</ControlTemplate> | |
</Setter.Value> | |
</Setter> | |
</Style> | |
<ControlTemplate x:Key="ComboBoxEditableTemplate" TargetType="{x:Type ComboBox}"> | |
<Grid x:Name="templateRoot" SnapsToDevicePixels="true"> | |
<Grid.ColumnDefinitions> | |
<ColumnDefinition Width="*"/> | |
<ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0"/> | |
</Grid.ColumnDefinitions> | |
<Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" Placement="Bottom" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}"> | |
<theme:SystemDropShadowChrome x:Name="shadow" Color="Transparent" MinWidth="{Binding ActualWidth, ElementName=templateRoot}" MaxHeight="{TemplateBinding MaxDropDownHeight}"> | |
<Border x:Name="dropDownBorder" Background="#000014" BorderThickness="1" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" CornerRadius="5"> | |
<ScrollViewer x:Name="DropDownScrollViewer"> | |
<Grid x:Name="grid" RenderOptions.ClearTypeHint="Enabled"> | |
<Canvas x:Name="canvas" HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0"> | |
<Rectangle x:Name="opaqueRect" Fill="{Binding Background, ElementName=dropDownBorder}" Height="{Binding ActualHeight, ElementName=dropDownBorder}" Width="{Binding ActualWidth, ElementName=dropDownBorder}"/> | |
</Canvas> | |
<ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> | |
</Grid> | |
</ScrollViewer> | |
</Border> | |
</theme:SystemDropShadowChrome> | |
</Popup> | |
<ToggleButton x:Name="toggleButton" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Grid.ColumnSpan="2" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource ComboBoxToggleButton}"/> | |
<Border x:Name="border" Background="{StaticResource TextBox.Static.Background}" Margin="{TemplateBinding BorderThickness}"> | |
<TextBox x:Name="PART_EditableTextBox" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" Margin="{TemplateBinding Padding}" Style="{StaticResource ComboBoxEditableTextBox}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/> | |
</Border> | |
</Grid> | |
<ControlTemplate.Triggers> | |
<Trigger Property="IsEnabled" Value="false"> | |
<Setter Property="Opacity" TargetName="border" Value="0.56"/> | |
</Trigger> | |
<Trigger Property="IsKeyboardFocusWithin" Value="true"> | |
<Setter Property="Foreground" Value="Black"/> | |
</Trigger> | |
<Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true"> | |
<Setter Property="Margin" TargetName="shadow" Value="0,0,5,5"/> | |
<Setter Property="Color" TargetName="shadow" Value="#71000000"/> | |
</Trigger> | |
<Trigger Property="HasItems" Value="false"> | |
<Setter Property="Height" TargetName="dropDownBorder" Value="95"/> | |
</Trigger> | |
<MultiTrigger> | |
<MultiTrigger.Conditions> | |
<Condition Property="IsGrouping" Value="true"/> | |
<Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="false"/> | |
</MultiTrigger.Conditions> | |
<Setter Property="ScrollViewer.CanContentScroll" Value="false"/> | |
</MultiTrigger> | |
<Trigger Property="ScrollViewer.CanContentScroll" SourceName="DropDownScrollViewer" Value="false"> | |
<Setter Property="Canvas.Top" TargetName="opaqueRect" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}"/> | |
<Setter Property="Canvas.Left" TargetName="opaqueRect" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}"/> | |
</Trigger> | |
</ControlTemplate.Triggers> | |
</ControlTemplate> | |
<ControlTemplate x:Key="ComboBoxTemplate" TargetType="{x:Type ComboBox}"> | |
<Grid Background="{TemplateBinding Background}" x:Name="templateRoot" SnapsToDevicePixels="true"> | |
<Grid.ColumnDefinitions> | |
<ColumnDefinition Width="*"/> | |
<ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0"/> | |
</Grid.ColumnDefinitions> | |
<Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Margin="1" Placement="Bottom" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}"> | |
<theme:SystemDropShadowChrome x:Name="shadow" Color="Transparent" MinWidth="{Binding ActualWidth, ElementName=templateRoot}" MaxHeight="{TemplateBinding MaxDropDownHeight}"> | |
<Border x:Name="dropDownBorder" BorderThickness="1" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" Background="#000014"> | |
<ScrollViewer x:Name="DropDownScrollViewer"> | |
<Grid x:Name="grid" RenderOptions.ClearTypeHint="Enabled"> | |
<Canvas x:Name="canvas" HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0"> | |
<Rectangle x:Name="opaqueRect" Fill="{Binding Background, ElementName=dropDownBorder}" Height="{Binding ActualHeight, ElementName=dropDownBorder}" Width="{Binding ActualWidth, ElementName=dropDownBorder}"/> | |
</Canvas> | |
<ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> | |
</Grid> | |
</ScrollViewer> | |
</Border> | |
</theme:SystemDropShadowChrome> | |
</Popup> | |
<ToggleButton x:Name="toggleButton" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Grid.ColumnSpan="2" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource ComboBoxToggleButton}"/> | |
<ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" Content="{TemplateBinding SelectionBoxItem}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" IsHitTestVisible="false" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> | |
</Grid> | |
<ControlTemplate.Triggers> | |
<Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true"> | |
<Setter Property="Margin" TargetName="shadow" Value="0,0,5,5"/> | |
<Setter Property="Color" TargetName="shadow" Value="#71000000"/> | |
</Trigger> | |
<Trigger Property="HasItems" Value="false"> | |
<Setter Property="Height" TargetName="dropDownBorder" Value="95"/> | |
</Trigger> | |
<MultiTrigger> | |
<MultiTrigger.Conditions> | |
<Condition Property="IsGrouping" Value="true"/> | |
<Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="false"/> | |
</MultiTrigger.Conditions> | |
<Setter Property="ScrollViewer.CanContentScroll" Value="false"/> | |
</MultiTrigger> | |
<Trigger Property="ScrollViewer.CanContentScroll" SourceName="DropDownScrollViewer" Value="false"> | |
<Setter Property="Canvas.Top" TargetName="opaqueRect" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}"/> | |
<Setter Property="Canvas.Left" TargetName="opaqueRect" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}"/> | |
</Trigger> | |
</ControlTemplate.Triggers> | |
</ControlTemplate> | |
<Style x:Key="ComboBoxStyle1" TargetType="{x:Type ComboBox}"> | |
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual2}"/> | |
<Setter Property="Background" Value="{StaticResource ComboBox.Static.Background}"/> | |
<Setter Property="BorderBrush" Value="{StaticResource ComboBox.Static.Border}"/> | |
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/> | |
<Setter Property="BorderThickness" Value="1"/> | |
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/> | |
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/> | |
<Setter Property="Padding" Value="6,3,5,3"/> | |
<Setter Property="ScrollViewer.CanContentScroll" Value="true"/> | |
<Setter Property="ScrollViewer.PanningMode" Value="Both"/> | |
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/> | |
<Setter Property="Template" Value="{StaticResource ComboBoxTemplate}"/> | |
<Style.Triggers> | |
<Trigger Property="IsEditable" Value="true"> | |
<Setter Property="IsTabStop" Value="false"/> | |
<Setter Property="Padding" Value="2"/> | |
<Setter Property="Template" Value="{StaticResource ComboBoxEditableTemplate}"/> | |
</Trigger> | |
<Trigger Property="IsMouseOver" Value="True"> | |
<Setter Property="Foreground" Value="#fff"/> | |
</Trigger> | |
</Style.Triggers> | |
</Style> |
MainWindow.xaml
Gavilya/Gavilya/MainWindow.xaml
Lines 165 to 173 in ec7d8a6
<ComboBox MaxWidth="400" Name="SearchBox" Grid.Column="3" BorderThickness="2" FontWeight="Bold" VerticalAlignment="Stretch" Margin="3 7" IsEditable="True" WindowChrome.IsHitTestVisibleInChrome="True" TextBoxBase.TextChanged="SearchBox_TextChanged" GotFocus="SearchBox_GotFocus" KeyUp="SearchBox_KeyUp"> | |
<ComboBox.Style> | |
<Style TargetType="ComboBox"> | |
<Setter Property="Template" Value="{StaticResource ComboBoxEditableTemplate}"/> | |
<Setter Property="ItemContainerStyle" Value="{StaticResource ItemStyle}" ></Setter> | |
</Style> | |
</ComboBox.Style> | |
</ComboBox> |
GamesCardsPages.xaml.cs
Gavilya/Gavilya/Pages/GamesCardsPages.xaml.cs
Lines 63 to 68 in ec7d8a6
foreach (GameInfo gameInfo in Definitions.Games) // For each game | |
{ | |
var game = new GameCard(gameInfo, GavilyaPages.Cards, false, recommandedGames.Contains(gameInfo)); | |
GamePresenter.Children.Add(game); // Add the game | |
Definitions.MainWindow.SearchBox.Items.Add(new SearchItem(game)); | |
} |
Beta Was this translation helpful? Give feedback.
All reactions
-
Thanks 🙏🏻 |
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
The search box is a
ComboBox
with theIsEditable
property set totrue
. A method adds in itsItems
each game of the user. To not only display the name of the game, but also its icon, I used theSearchItem
UserControl
. For the search function, it's the default autocompletion of theComboBox
. I just had to override theToString()
method of theSearchItem
. I also used a custom style for theComboBox
.You can check the code implementation here:
SearchItem
XAML
Gavilya/Gavilya/UserControls/SearchItem.xaml
Lines 1 to 18 in ec7d8a6