Skip to content

Instantly share code, notes, and snippets.

/Main.xaml Secret

Created May 26, 2017 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/a10df9e36bd168f9652a8546a236107f to your computer and use it in GitHub Desktop.
Save anonymous/a10df9e36bd168f9652a8546a236107f to your computer and use it in GitHub Desktop.
<local:RequirementSelect Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Margin="0 5 0 0" Value="{Binding Req, Mode=TwoWay}" />
<UserControl x:Class="HealthNav.Views.Controls.LetterTemplate.RequirementSelect"
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:HealthNav.Views.Controls.LetterTemplate"
mc:Ignorable="d" >
<Grid>
<StackPanel Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal">
<Label Margin="0 0 5 0">Voluntary:</Label>
<CheckBox Name="ckbVoluntary" Margin="0 0 10 0" Checked="ckbRequirement_Checked" Unchecked="ckbRequirement_Checked" VerticalAlignment="Center" />
<Label Margin="0 0 5 0">Mandatory:</Label>
<CheckBox Name="ckbMandatory" Checked="ckbRequirement_Checked" Unchecked="ckbRequirement_Checked" VerticalAlignment="Center" />
</StackPanel>
</Grid>
</UserControl>
using System;
using System.Windows;
using System.Windows.Controls;
namespace HealthNav.Views.Controls.LetterTemplate {
/// <summary>
/// Interaction logic for RequirementSelect.xaml
/// </summary>
public partial class RequirementSelect : UserControl {
public RequirementSelect() {
InitializeComponent();
}
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(
"Value", typeof(Boolean), typeof(RequirementSelect), new PropertyMetadata(false));
public string Value {
get {
return (string)this.GetValue(ValueProperty); ;
}
set {
if (value.ToUpper().StartsWith("M")) {
ckbMandatory.IsChecked = true;
ckbVoluntary.IsChecked = false;
} else if (value.ToUpper().StartsWith("V")) {
ckbMandatory.IsChecked = false;
ckbVoluntary.IsChecked = true;
} else {
ckbMandatory.IsChecked = false;
ckbVoluntary.IsChecked = false;
}
this.SetValue(ValueProperty, value);
}
}
private void ckbRequirement_Checked(object sender, RoutedEventArgs e) {
CheckBox thisCheckbox = (CheckBox)sender;
if (thisCheckbox.IsChecked == true) {
CheckBox otherCheckbox = (thisCheckbox == ckbVoluntary ? ckbMandatory : ckbVoluntary);
if (otherCheckbox.IsChecked == true) {
SetHooks(false);
otherCheckbox.IsChecked = false;
SetHooks(true);
}
}
string val = "N";
if (ckbVoluntary.IsChecked == true)
val = "V";
else if (ckbMandatory.IsChecked == true)
val = "M";
this.SetValue(ValueProperty, val);
}
private void SetHooks(bool Add) {
if (Add) {
ckbVoluntary.Checked += ckbRequirement_Checked;
ckbVoluntary.Unchecked += ckbRequirement_Checked;
ckbMandatory.Checked += ckbRequirement_Checked;
ckbMandatory.Unchecked += ckbRequirement_Checked;
} else {
ckbVoluntary.Checked -= ckbRequirement_Checked;
ckbVoluntary.Unchecked -= ckbRequirement_Checked;
ckbMandatory.Checked -= ckbRequirement_Checked;
ckbMandatory.Unchecked -= ckbRequirement_Checked;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment