Permalink
Browse files

Included ComboBoxEx

  • Loading branch information...
mbrenn committed Nov 18, 2017
1 parent 0883ff8 commit 67b7eb219720000a8403064d986f061e16bed383
@@ -86,6 +86,7 @@
<Compile Include="Forms\Base\ViewDefinition.cs" />
<Compile Include="Forms\Lists\ExtentList.cs" />
<Compile Include="Forms\Lists\ItemsInExtentList.cs" />
<Compile Include="Helper\ComboBoxEx.cs" />
<Compile Include="INavigationGuest.cs" />
<Compile Include="INavigationHost.cs" />
<Compile Include="Navigation\ControlNavigation.cs" />
@@ -3,6 +3,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:helper="clr-namespace:DatenMeisterWPF.Helper"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
@@ -12,7 +13,7 @@
</UserControl.Resources>
<DockPanel>
<StackPanel Orientation="Horizontal" x:Name="Toolbar" DockPanel.Dock="Top" HorizontalAlignment="Right" Margin="10,0,10,0">
<ComboBox x:Name="ViewList" SelectionChanged="ViewList_OnSelectionChanged"></ComboBox>
<helper:ComboBoxEx x:Name="ViewList" SelectionChanged="ViewList_OnSelectionChanged"></helper:ComboBoxEx>
<TextBox x:Name="SearchField" Width="200" TextChanged="SearchField_OnTextChanged"></TextBox>
</StackPanel>
<StackPanel Orientation="Horizontal" x:Name="ButtonBar" DockPanel.Dock="Bottom" HorizontalAlignment="Right" Margin="10">
@@ -0,0 +1,39 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
namespace DatenMeisterWPF.Helper
{
/// <summary>
/// Extents the combobox by setting the width of the combobox to the largest element.
/// I have no clue, why this function is not included into WPF itself
/// </summary>
public class ComboBoxEx : ComboBox
{
/// <summary>
/// Stores the index of the selected template
/// </summary>
private int _selected;
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_selected = SelectedIndex;
SelectedIndex = -1;
Loaded += ComboBoxEx_Loaded;
}
private void ComboBoxEx_Loaded(object sender, RoutedEventArgs e)
{
if (Items.Count > 0)
{
var popup = GetTemplateChild("PART_Popup") as Popup;
var content = popup?.Child as FrameworkElement;
content?.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
MinHeight = (content?.DesiredSize.Height ?? 0) / Items.Count;
MinWidth = (content?.DesiredSize.Width) ?? 0;
SelectedIndex = _selected;
}
}
}
}

0 comments on commit 67b7eb2

Please sign in to comment.