Files
BeWoPlaner/BeWo/View/Controls/ComboBoxTreeViewControl.xaml.cs

201 lines
6.4 KiB
C#
Raw Normal View History

2016-06-27 01:45:38 +02:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
2016-06-27 01:45:38 +02:00
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.ClientPartials;
namespace BeWo.View.Controls
{
public partial class ComboBoxTreeViewControl
{
public double ParentWindowHeight
{
get { return (double) GetValue(ParentWindowHeightProperty); }
set { SetValue(ParentWindowHeightProperty, value); }
}
public static readonly DependencyProperty ParentWindowHeightProperty = DependencyProperty.Register("ParentWindowHeight", typeof (double), typeof (ComboBoxTreeViewControl), new FrameworkPropertyMetadata(500.0));
2016-06-27 01:45:38 +02:00
public List<SupportConceptGoalDC> TreeViewSourceList
{
get { return (List<SupportConceptGoalDC>)GetValue(ListProperty); }
set
{
SetValue(ListProperty, value);
ShowCheckedValues();
}
}
public static readonly DependencyProperty ListProperty = DependencyProperty.Register("TreeViewSourceList", typeof (List<SupportConceptGoalDC>), typeof (ComboBoxTreeViewControl), new FrameworkPropertyMetadata(new List<SupportConceptGoalDC>()));
2016-06-27 01:45:38 +02:00
public ComboBoxTreeViewControl()
{
InitializeComponent();
DataContext = this;
}
private void ShowCheckedValues()
{
GoalCount = 0;
var selectedGoals = GetSelectedGoals();
var allSelected = selectedGoals.Count == GoalCount && GoalCount > 0;
2016-06-27 01:45:38 +02:00
var ToolTipString = selectedGoals.Aggregate(string.Empty, (s, dc) => s + (dc.TypeDescription + "; "));
2016-06-27 01:45:38 +02:00
DeSelectAllCheckBox.IsChecked = allSelected;
Imitationheader.Text = ToolTipString;
if (string.IsNullOrWhiteSpace(ToolTipString))
{
Imitationheader.ToolTip = null;
return;
}
var splittedToolTip = ToolTipString.Split(';');
2016-06-27 01:45:38 +02:00
ToolTipString = string.Empty;
foreach (var item in splittedToolTip.Where(x => x != " "))
{
ToolTipString += item.Trim(' ');
if (splittedToolTip.Where(x => x != " ").ToList().IndexOf(item) < splittedToolTip.Count(x => x != " ") - 1)
{
ToolTipString += "\n";
}
2016-06-27 01:45:38 +02:00
}
Imitationheader.ToolTip = ToolTipString;
}
private List<ValueListEntryDC> GetSelectedGoals()
{
var goals = new List<ValueListEntryDC>();
AddCheckedGoals(TreeViewSourceList, goals);
return goals;
}
private int GoalCount;
private void AddCheckedGoals(IEnumerable<SupportConceptGoalDC> goals, ICollection<ValueListEntryDC> selectedGoals)
2016-06-27 01:45:38 +02:00
{
foreach (var item in goals)
2016-06-27 01:45:38 +02:00
{
if (item.Children == null || item.Children.Count == 0)
{
//if (item.GoalEntryDC.Type.Equals(ValueListEntryType.SupportConceptGoalType) || item.GoalEntryDC.Type.Equals(ValueListEntryType.SupportConceptIndividualGoalType))
//{
GoalCount++;
if (item.IsChecked)
{
selectedGoals.Add(item.GoalEntryDC);
}
//}
}
else
{
AddCheckedGoals(item.Children, selectedGoals);
}
}
}
private void OpenPopUpBtnClick(object sender, EventArgs e)
{
openPopup();
}
private void openPopup()
{
TreeViewPopup.Placement = PlacementMode.RelativePoint;
TreeViewPopup.PlacementTarget = Imitationheader;
TreeViewPopup.VerticalOffset = Imitationheader.Height;
2016-06-27 01:45:38 +02:00
TreeViewPopup.HorizontalOffset = 0;
TreeViewPopup.MinWidth = Imitationheader.Width;
TreeViewPopup.IsOpen = true;
2016-06-27 01:45:38 +02:00
if (ParentWindowHeight == 0)
{
2016-06-27 01:45:38 +02:00
ParentWindowHeight = 500;
}
2016-06-27 01:45:38 +02:00
OpenPopUpBtn.IsEnabled = false;
}
private void PopUpClosedEvent(object sender, EventArgs eventArgs)
{
ShowCheckedValues();
cbtv_search.Text = string.Empty;
2016-06-27 01:45:38 +02:00
OpenPopUpBtn.IsEnabled = true;
}
private void ApplyBtnClose(object sender, EventArgs e)
{
TreeViewPopup.IsOpen = false;
}
public void ResetControl()
{
TreeViewSourceList = new List<SupportConceptGoalDC>();
Imitationheader.Text = string.Empty;
Imitationheader.ToolTip = null;
2016-06-27 01:45:38 +02:00
DeSelectAllCheckBox.IsChecked = false;
}
private void Tree1_OnLoaded(object sender, RoutedEventArgs e)
{
if (ParentWindowHeight >= TreeViewPopup.VerticalOffset)
{
TreeViewPopup.MaxHeight = ParentWindowHeight - TreeViewPopup.VerticalOffset - ParentWindowHeight/4;
}
2016-06-27 01:45:38 +02:00
}
private void Bd_OnClick(object sender, RoutedEventArgs e)
{
ShowCheckedValues();
}
private void DeSelectAllOnClick(object sender, RoutedEventArgs e)
{
var cb = (CheckBox)sender;
if (!cb.IsChecked.HasValue)
{
return;
}
2016-06-27 01:45:38 +02:00
foreach (var item in TreeViewSourceList)
{
item.IsChecked = cb.IsChecked.Value;
2016-06-27 01:45:38 +02:00
foreach (var item2 in item.Children)
{
item2.IsChecked = cb.IsChecked.Value;
}
2016-06-27 01:45:38 +02:00
}
ShowCheckedValues();
}
private void BdText_OnMouseDown(object sender, MouseButtonEventArgs e)
{
var SupportConceptGoal = ((TextBlock)sender).Tag as SupportConceptGoalDC;
if(SupportConceptGoal != null)
{
SupportConceptGoal.IsChecked = !SupportConceptGoal.IsChecked;
}
ShowCheckedValues();
2016-06-27 01:45:38 +02:00
}
}
}