Skip to content

Commit 4d5420b

Browse files
authored
Merge pull request #4929 from Vogel612/fix/language-change-exception
Fix language change exception
2 parents dd68164 + 702f18c commit 4d5420b

13 files changed

+231
-126
lines changed

Rubberduck.Core/Rubberduck.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<DisabledWarnings>$(DisabledWarnings);1591</DisabledWarnings>
1313
<ApplicationIcon>Ducky.ico</ApplicationIcon>
1414
<!-- Give a fixed version to not blow XAML generated code to smithereens -->
15+
<!-- This also fixes "Input string was not in the correct format" error message when referring to the current assembly in an XAML-Namespace -->
1516
<AssemblyVersion>2.4.1</AssemblyVersion>
1617
</PropertyGroup>
1718
<Import Project="..\RubberduckBaseProject.csproj" />

Rubberduck.Core/UI/AddRemoveReferences/AddRemoveReferencesWindow.xaml

Lines changed: 6 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
1010
xmlns:controls="clr-namespace:Rubberduck.UI.Controls"
1111
xmlns:system="clr-namespace:System;assembly=mscorlib"
12-
mc:Ignorable="d"
12+
mc:Ignorable="d"
1313
d:DesignHeight="380" d:DesignWidth="600"
1414
d:DataContext="{d:DesignInstance local:AddRemoveReferencesViewModel}">
1515
<UserControl.Resources>
@@ -26,7 +26,6 @@
2626
<local:ReferenceStatusImageSourceConverter x:Key="StatusToIcon" />
2727
<local:PriorityButtonVisibilityConverter x:Key="PriorityButtonVisibility" />
2828
<local:PriorityButtonImageSourceConverter x:Key="PriorityButtonIcon" />
29-
<converters:SearchImageSourceConverter x:Key="SearchToIcon" />
3029
<converters:BooleanToNonDimmedBrushConverter x:Key="BooleanToNonDimmed" />
3130
<converters:BoolToHiddenVisibilityConverter x:Key="ProjectVisibilityConverter" />
3231

@@ -35,39 +34,6 @@
3534
<Setter Property="Height" Value="24" />
3635
<Setter Property="Padding" Value="10,0" />
3736
</Style>
38-
<Style x:Key="PlaceHolder" TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
39-
<Setter Property="Template">
40-
<Setter.Value>
41-
<ControlTemplate TargetType="{x:Type TextBox}">
42-
<Grid>
43-
<TextBox Text="{Binding Path=Text,
44-
RelativeSource={RelativeSource TemplatedParent},
45-
Mode=TwoWay,
46-
UpdateSourceTrigger=PropertyChanged}"
47-
x:Name="textSource"
48-
Background="Transparent"
49-
Panel.ZIndex="2"
50-
VerticalContentAlignment="Center" />
51-
<TextBox Text="{TemplateBinding Tag}" Background="{TemplateBinding Background}" Panel.ZIndex="1">
52-
<TextBox.Style>
53-
<Style TargetType="{x:Type TextBox}">
54-
<Setter Property="Foreground" Value="Transparent"/>
55-
<Setter Property="VerticalContentAlignment" Value="Center"/>
56-
<Style.Triggers>
57-
<DataTrigger Binding="{Binding Path=Text, Source={x:Reference textSource}}" Value="">
58-
<Setter Property="Foreground" Value="LightGray"/>
59-
</DataTrigger>
60-
</Style.Triggers>
61-
</Style>
62-
</TextBox.Style>
63-
</TextBox>
64-
</Grid>
65-
</ControlTemplate>
66-
</Setter.Value>
67-
</Setter>
68-
<Setter Property="Margin" Value="0" />
69-
<Setter Property="VerticalAlignment" Value="Center" />
70-
</Style>
7137
<Style TargetType="{x:Type TabItem}">
7238
<Setter Property="Background" Value="Transparent" />
7339
<Setter Property="Template">
@@ -204,32 +170,11 @@
204170
BorderThickness="1"
205171
Margin="0,5"
206172
Padding="2">
207-
<Grid>
208-
<Grid.ColumnDefinitions>
209-
<ColumnDefinition Width="*" />
210-
<ColumnDefinition Width="20" />
211-
</Grid.ColumnDefinitions>
212-
<TextBox Name="SearchBox" Grid.Column="0">
213-
<TextBox.Style>
214-
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource PlaceHolder}">
215-
<Setter Property="Height" Value="20" />
216-
<Setter Property="Width" Value="Auto" />
217-
<Setter Property="Tag" Value="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=References_SearchPlaceholder}" />
218-
<Setter Property="Text" Value="{Binding Search, UpdateSourceTrigger=PropertyChanged}" />
219-
</Style>
220-
</TextBox.Style>
221-
</TextBox>
222-
<Button Name="SearchButton" Grid.Column="1" Command="{Binding ClearSearchCommand}"
223-
BorderBrush="{x:Static SystemColors.ControlLightBrush}"
224-
Background="Transparent"
225-
Width="20" Height="20" Padding="0" Margin="0,1">
226-
<Image VerticalAlignment="Center" HorizontalAlignment="Center"
227-
Width="16" Height="16" Source="{Binding Search, Converter={StaticResource SearchToIcon}, UpdateSourceTrigger=PropertyChanged}" />
228-
<i:Interaction.Behaviors>
229-
<controls:FocusElementAfterClickBehavior FocusElement="{Binding ElementName=SearchBox, Mode=OneWay}"/>
230-
</i:Interaction.Behaviors>
231-
</Button>
232-
</Grid>
173+
<controls:SearchBox x:Name="SearchBox" Grid.Column="0"
174+
Background="{x:Static SystemColors.WindowBrush}"
175+
Width="Auto"
176+
Text="{Binding Search, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
177+
Hint="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=References_SearchPlaceholder}" />
233178
</Border>
234179
<Border Grid.Row="1" Grid.Column="0">
235180
<ListView Name="LibrarySelect" SelectedItem="{Binding SelectedLibrary, Mode=TwoWay}"

Rubberduck.Core/UI/CodeExplorer/CodeExplorerControl.xaml

Lines changed: 10 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
77
xmlns:codeExplorer="clr-namespace:Rubberduck.Navigation.CodeExplorer"
8-
xmlns:controls="clr-namespace:Rubberduck.UI.Controls"
9-
xmlns:converters="clr-namespace:Rubberduck.UI.Converters"
10-
xmlns:local="clr-namespace:Rubberduck.UI.CodeExplorer"
8+
xmlns:controls="clr-namespace:Rubberduck.UI.Controls;assembly="
9+
xmlns:converters="clr-namespace:Rubberduck.UI.Converters;assembly="
10+
xmlns:local="clr-namespace:Rubberduck.UI.CodeExplorer;assembly="
1111
ResxExtension.DefaultResxName="Rubberduck.Resources.CodeExplorer.CodeExplorerUI"
1212
Language="{UICulture}"
1313
Name="CodeExplorer"
@@ -48,7 +48,6 @@
4848
<converters:BoolToHiddenVisibilityConverter x:Key="BoolToHiddenVisibility" />
4949
<converters:BooleanToDimmedBrushConverter x:Key="BooleanToDimmed" />
5050
<converters:TemplateCommandParameterToTupleConverter x:Key="TemplateCommandParameterToTuple" />
51-
<converters:SearchImageSourceConverter x:Key="SearchToIcon" />
5251
<converters:InvertBoolValueConverter x:Key="NotBool" />
5352
<converters:CodeExplorerNodeToIconConverter x:Key="NodeToIcon" />
5453
<converters:AccessibilityToIconConverter x:Key="AccessibilityToIcon" />
@@ -64,37 +63,6 @@
6463
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black" />
6564
<SolidColorBrush x:Key="{x:Static SystemColors.ControlTextBrushKey}" Color="Black" />
6665

67-
<Style x:Key="PlaceHolder" TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
68-
<Setter Property="Template">
69-
<Setter.Value>
70-
<ControlTemplate TargetType="{x:Type TextBox}">
71-
<Grid>
72-
<TextBox Text="{Binding Path=Text, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
73-
x:Name="textSource"
74-
Background="Transparent"
75-
Panel.ZIndex="2"
76-
VerticalContentAlignment="Center"/>
77-
<TextBox Text="{TemplateBinding Tag}" Background="{TemplateBinding Background}" Panel.ZIndex="1">
78-
<TextBox.Style>
79-
<Style TargetType="{x:Type TextBox}">
80-
<Setter Property="Foreground" Value="Transparent"/>
81-
<Setter Property="VerticalContentAlignment" Value="Center"/>
82-
<Style.Triggers>
83-
<DataTrigger Binding="{Binding Path=Text, Source={x:Reference textSource}}" Value="">
84-
<Setter Property="Foreground" Value="LightGray"/>
85-
</DataTrigger>
86-
</Style.Triggers>
87-
</Style>
88-
</TextBox.Style>
89-
</TextBox>
90-
</Grid>
91-
</ControlTemplate>
92-
</Setter.Value>
93-
</Setter>
94-
<Setter Property="Margin" Value="0" />
95-
<Setter Property="VerticalAlignment" Value="Center" />
96-
</Style>
97-
9866
<CompositeCollection x:Key="AddModuleCommands">
9967
<MenuItem Header="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_AddVBFormText}"
10068
Command="{Binding AddVBFormCommand}"
@@ -419,32 +387,13 @@
419387
BorderBrush="{x:Static SystemColors.ActiveBorderBrush}"
420388
BorderThickness="1"
421389
Padding="2">
422-
<Grid>
423-
<Grid.ColumnDefinitions>
424-
<ColumnDefinition Width="*" />
425-
<ColumnDefinition Width="20" />
426-
</Grid.ColumnDefinitions>
427-
<TextBox Name="SearchBox" Grid.Column="0">
428-
<TextBox.Style>
429-
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource PlaceHolder}">
430-
<Setter Property="Height" Value="20" />
431-
<Setter Property="Width" Value="Auto" />
432-
<Setter Property="Tag" Value="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI, Key=CodeExplorer_SearchPlaceholder}" />
433-
<Setter Property="Text" Value="{Binding Search, UpdateSourceTrigger=PropertyChanged}" />
434-
</Style>
435-
</TextBox.Style>
436-
</TextBox>
437-
<Button Name="SearchButton" Grid.Column="1" Command="{Binding ClearSearchCommand}"
438-
BorderBrush="{x:Static SystemColors.ControlLightBrush}"
439-
Background="Transparent"
440-
Width="20" Height="20" Padding="0" Margin="0,1">
441-
<Image VerticalAlignment="Center" HorizontalAlignment="Center"
442-
Width="16" Height="16" Source="{Binding Search, Converter={StaticResource SearchToIcon}, UpdateSourceTrigger=PropertyChanged}" />
443-
<i:Interaction.Behaviors>
444-
<controls:FocusElementAfterClickBehavior FocusElement="{Binding ElementName=SearchBox, Mode=OneWay}"/>
445-
</i:Interaction.Behaviors>
446-
</Button>
447-
</Grid>
390+
<controls:SearchBox x:Name="SearchBox"
391+
Background="{x:Static SystemColors.WindowBrush}"
392+
Text="{Binding Search, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
393+
Hint="{Resx ResxName=Rubberduck.Resources.CodeExplorer.CodeExplorerUI,
394+
Key=CodeExplorer_SearchPlaceholder}"
395+
Grid.Column="0"
396+
Width="Auto"/>
448397
</Border>
449398

450399
<TreeView x:Name="ProjectTree"
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System.Windows;
2+
using System.Windows.Controls.Primitives;
3+
4+
namespace Rubberduck.UI.Controls.Behavior
5+
{
6+
using ButtonBehavior = System.Windows.Interactivity.Behavior<ButtonBase>;
7+
8+
public class ResetValueBehavior : ButtonBehavior
9+
{
10+
private ButtonBase _associatedButton;
11+
12+
protected override void OnAttached()
13+
{
14+
_associatedButton = AssociatedObject;
15+
16+
_associatedButton.Click += AssociatedButtonClick;
17+
}
18+
19+
protected override void OnDetaching()
20+
{
21+
_associatedButton.Click -= AssociatedButtonClick;
22+
}
23+
24+
private void AssociatedButtonClick(object sender, RoutedEventArgs e)
25+
{
26+
Affects = Default;
27+
}
28+
29+
public object Affects
30+
{
31+
get => GetValue(AffectsProperty);
32+
set
33+
{
34+
var oldValue = Affects;
35+
SetValue(AffectsProperty, value);
36+
OnPropertyChanged(new DependencyPropertyChangedEventArgs(AffectsProperty, oldValue, value));
37+
}
38+
}
39+
40+
public object Default
41+
{
42+
get => GetValue(DefaultProperty);
43+
set
44+
{
45+
var oldValue = Default;
46+
SetValue(DefaultProperty, value);
47+
OnPropertyChanged(new DependencyPropertyChangedEventArgs(DefaultProperty, oldValue, value));
48+
}
49+
}
50+
51+
// Using a DependencyProperty as the backing store for Affects.
52+
// This enables animation, styling, binding, etc...
53+
public static readonly DependencyProperty AffectsProperty =
54+
DependencyProperty.Register("Affects", typeof(object), typeof(ResetValueBehavior), new UIPropertyMetadata());
55+
public static readonly DependencyProperty DefaultProperty =
56+
DependencyProperty.Register("Default", typeof(object), typeof(ResetValueBehavior), new UIPropertyMetadata(defaultValue: null));
57+
}
58+
}

Rubberduck.Core/UI/Controls/NumberPicker.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.ComponentModel;
33
using System.Windows;
4+
using System.Windows.Controls;
45
using Rubberduck.Settings;
56

67
// credit to http://stackoverflow.com/a/2752538
@@ -9,7 +10,7 @@ namespace Rubberduck.UI.Controls
910
/// <summary>
1011
/// Interaction logic for NumberPicker.xaml
1112
/// </summary>
12-
public partial class NumberPicker : IDataErrorInfo
13+
public partial class NumberPicker : UserControl, IDataErrorInfo
1314
{
1415
public static readonly DependencyProperty NumValueProperty =
1516
DependencyProperty.Register(nameof(NumValue), typeof(int), typeof(NumberPicker), new UIPropertyMetadata(default(int), PropertyChangedCallback));
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<UserControl x:Class="Rubberduck.UI.Controls.SearchBox"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
7+
xmlns:local="clr-namespace:Rubberduck.UI.Controls;assembly="
8+
xmlns:ib="clr-namespace:Rubberduck.UI.Controls.Behavior;assembly="
9+
xmlns:converters="clr-namespace:Rubberduck.UI.Converters;assembly="
10+
mc:Ignorable="d"
11+
MinWidth="50" MinHeight="20"
12+
Height="20"
13+
Name="Root"
14+
d:DesignHeight="20" d:DesignWidth="400"
15+
d:DataContext="{d:DesignInstance local:SearchBox, IsDesignTimeCreatable=True}">
16+
<Grid>
17+
<Grid.ColumnDefinitions>
18+
<ColumnDefinition Width="*"/>
19+
<ColumnDefinition Width="20" />
20+
</Grid.ColumnDefinitions>
21+
<TextBox Text="{Binding Path=Text, ElementName=Root, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
22+
x:Name="ValueContainer"
23+
Background="Transparent"
24+
Panel.ZIndex="2"
25+
VerticalContentAlignment="Center"
26+
Width="Auto"
27+
Grid.Row="0" Grid.Column="0"/>
28+
<!-- this is the actual hint container, it's BELOW the displaying control -->
29+
<TextBox Text="{Binding Path=Hint, ElementName=Root, Mode=OneWay}"
30+
Background="{Binding Path=Background, ElementName=Root}"
31+
Width="{Binding Path=ActualWidth, ElementName=ValueContainer}"
32+
Height="{Binding Path=ActualHeight, ElementName=ValueContainer}"
33+
Panel.ZIndex="1"
34+
VerticalContentAlignment="Center"
35+
Grid.Row="0" Grid.Column="0">
36+
<TextBox.Style>
37+
<Style TargetType="{x:Type TextBox}">
38+
<!-- Setter needs to be within this type to be overwritable with a trigger -->
39+
<Setter Property="Foreground" Value="Transparent" />
40+
<Style.Triggers>
41+
<DataTrigger Binding="{Binding Path=Text, Source={x:Reference ValueContainer}}" Value="">
42+
<Setter Property="Foreground" Value="{x:Static SystemColors.GrayTextBrush}"/>
43+
</DataTrigger>
44+
</Style.Triggers>
45+
</Style>
46+
</TextBox.Style>
47+
</TextBox>
48+
<Button Name="SearchButton" Grid.Column="1" Command="{Binding ClearSearchCommand}"
49+
BorderBrush="{x:Static SystemColors.ControlLightBrush}"
50+
Background="Transparent"
51+
Width="20" Height="20" Padding="0" Margin="0,1"
52+
xmlns:sys="clr-namespace:System;assembly=mscorlib">
53+
<Button.Resources>
54+
<converters:SearchImageSourceConverter x:Key="SearchToIcon" />
55+
</Button.Resources>
56+
<Image VerticalAlignment="Center" HorizontalAlignment="Center"
57+
Width="16" Height="16"
58+
Source="{Binding Text, ElementName=ValueContainer,
59+
Converter={StaticResource SearchToIcon},
60+
UpdateSourceTrigger=PropertyChanged}" />
61+
<i:Interaction.Behaviors>
62+
<local:FocusElementAfterClickBehavior FocusElement="{x:Reference ValueContainer}"/>
63+
<ib:ResetValueBehavior Affects="{Binding Path=Text, ElementName=ValueContainer, Mode=OneWayToSource}"
64+
Default="{x:Static sys:String.Empty}"/>
65+
</i:Interaction.Behaviors>
66+
</Button>
67+
</Grid>
68+
</UserControl>

0 commit comments

Comments
 (0)