-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
621 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Windows.Data; | ||
|
||
namespace Arma.Studio.Data.UI.Converters | ||
{ | ||
public class OnEqualsConverter : IValueConverter | ||
{ | ||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
if (!(parameter is string pstring)) | ||
{ | ||
return value.GetType().IsEquivalentTo(parameter.GetType()) ? value.Equals(parameter) : value; | ||
} | ||
string[] parr = pstring.Split('|'); | ||
var valueType = value.GetType(); | ||
if (value.Equals(valueType.IsEnum ? Enum.Parse(valueType, parr[0]) : System.Convert.ChangeType(parr[0], value.GetType()))) | ||
{ | ||
return System.Convert.ChangeType(parr[1], targetType); | ||
} | ||
|
||
return parr.Length == 3 ? System.Convert.ChangeType(parr[2], targetType) : value; | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
return value; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Controls.Primitives; | ||
using System.Windows.Markup; | ||
|
||
namespace Arma.Studio.Data.UI | ||
{ | ||
[ContentProperty(nameof(PopupContainer.Content))] | ||
public class PopupContainer : Control | ||
{ | ||
static PopupContainer() | ||
{ | ||
DefaultStyleKeyProperty.OverrideMetadata(typeof(PopupContainer), new FrameworkPropertyMetadata(typeof(PopupContainer))); | ||
} | ||
|
||
#region DependencyProperty: Content (System.Object) | ||
public static readonly DependencyProperty ContentProperty = DependencyProperty.Register( | ||
nameof(Content), typeof(object), typeof(PopupContainer)); | ||
public object Content { get => this.GetValue(ContentProperty); set => this.SetValue(ContentProperty, value); } | ||
#endregion | ||
#region DependencyProperty: Placement (System.Windows.Controls.Primitives.PlacementMode) | ||
public static readonly DependencyProperty PlacementProperty = DependencyProperty.Register( | ||
nameof(Placement), typeof(PlacementMode), typeof(PopupContainer)); | ||
public PlacementMode Placement { get => (PlacementMode)this.GetValue(PlacementProperty); set => this.SetValue(PlacementProperty, value); } | ||
#endregion | ||
#region DependencyProperty: PopupContent (System.Object) | ||
public static readonly DependencyProperty PopupContentProperty = DependencyProperty.Register( | ||
nameof(PopupContent), typeof(object), typeof(PopupContainer)); | ||
public object PopupContent { get => this.GetValue(PopupContentProperty); set => this.SetValue(PopupContentProperty, value); } | ||
#endregion | ||
#region DependencyProperty: PopupContentTemplate (System.Windows.DataTemplate) | ||
public static readonly DependencyProperty PopupContentTemplateProperty = DependencyProperty.Register( | ||
nameof(PopupContentTemplate), typeof(DataTemplate), typeof(PopupContainer)); | ||
public DataTemplate PopupContentTemplate { get => (DataTemplate)this.GetValue(PopupContentTemplateProperty); set => this.SetValue(PopupContentTemplateProperty, value); } | ||
#endregion | ||
#region DependencyProperty: PopupCanOpen (System.Boolean) | ||
public static readonly DependencyProperty PopupCanOpenProperty = DependencyProperty.Register( | ||
nameof(PopupCanOpen), typeof(bool), typeof(PopupContainer), new PropertyMetadata(true)); | ||
public bool PopupCanOpen { get => (bool)this.GetValue(PopupCanOpenProperty); set => this.SetValue(PopupCanOpenProperty, value); } | ||
#endregion | ||
#region RoutedEvent: PopupOpened | ||
public static readonly RoutedEvent PopupOpenedEvent = EventManager.RegisterRoutedEvent(nameof(PopupOpened), RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(PopupContainer)); | ||
public event RoutedEventHandler PopupOpened { add { this.AddHandler(PopupOpenedEvent, value); } remove { this.RemoveHandler(PopupOpenedEvent, value); } } | ||
protected void RaisePopupOpened() { this.RaiseEvent(new RoutedEventArgs(PopupOpenedEvent, this)); } | ||
#endregion | ||
|
||
public override void OnApplyTemplate() | ||
{ | ||
if (this.GetTemplateChild("PART_Popup") is Popup PART_Popup) | ||
{ | ||
PART_Popup.Opened += this.PART_Popup_Opened; | ||
PART_Popup.PreviewMouseDown += this.PART_Popup_PreviewMouseDown; | ||
} | ||
} | ||
|
||
private void PART_Popup_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) | ||
{ | ||
Application.Current.MainWindow.Activate(); | ||
} | ||
|
||
private void PART_Popup_Opened(object sender, EventArgs e) | ||
{ | ||
this.RaisePopupOpened(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<ResourceDictionary | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="clr-namespace:Arma.Studio.Data.UI"> | ||
<Style x:Key="{x:Type local:PopupContainer}" TargetType="{x:Type local:PopupContainer}"> | ||
<Setter Property="Background" Value="Transparent"/> | ||
<Setter Property="Placement" Value="Bottom"/> | ||
<Setter Property="Template"> | ||
<Setter.Value> | ||
<ControlTemplate TargetType="{x:Type local:PopupContainer}"> | ||
<Border x:Name="PART_Border" | ||
Background="{TemplateBinding Background}" | ||
BorderBrush="{TemplateBinding BorderBrush}" | ||
BorderThickness="{TemplateBinding BorderThickness}" | ||
Margin="{TemplateBinding Margin}" | ||
Padding="{TemplateBinding Padding}"> | ||
<Grid> | ||
<ContentPresenter x:Name="PART_Content"/> | ||
<Popup x:Name="PART_Popup" | ||
PlacementTarget="{Binding ElementName=PART_Border}" | ||
Placement="{TemplateBinding Placement}" | ||
> | ||
<ContentPresenter Content="{TemplateBinding PopupContent}"/> | ||
</Popup> | ||
</Grid> | ||
</Border> | ||
<ControlTemplate.Triggers> | ||
<Trigger Property="IsMouseOver" SourceName="PART_Popup" Value="True"> | ||
<Setter Property="IsOpen" Value="True" TargetName="PART_Popup"/> | ||
</Trigger> | ||
<Trigger Property="IsMouseOver" SourceName="PART_Border" Value="True"> | ||
<Setter Property="IsOpen" Value="True" TargetName="PART_Popup"/> | ||
</Trigger> | ||
<Trigger Property="PopupCanOpen" Value="False"> | ||
<Setter Property="IsOpen" Value="False" TargetName="PART_Popup"/> | ||
</Trigger> | ||
</ControlTemplate.Triggers> | ||
</ControlTemplate> | ||
</Setter.Value> | ||
</Setter> | ||
</Style> | ||
</ResourceDictionary> |
Oops, something went wrong.