1
0
mirror of https://github.com/chylex/Backup-Essentials.git synced 2025-07-25 22:59:02 +02:00

Added binding updating extension method

This commit is contained in:
chylex 2015-04-29 17:25:55 +02:00
parent 33a1eb079a
commit a64f4574a6
2 changed files with 30 additions and 0 deletions

View File

@ -140,6 +140,7 @@
<Compile Include="Utils\ProgramArgsParser.cs" />
<Compile Include="Utils\ScheduledUpdate.cs" />
<Compile Include="Utils\WindowsVersion.cs" />
<Compile Include="Utils\WpfExtensions.cs" />
<Page Include="BackupReportWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>

View File

@ -0,0 +1,29 @@
using System.Collections.Generic;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
namespace BackupEssentials.Utils{
static class WpfExtensions{
public static IEnumerable<DependencyObject> EnumerateMeAndChildren(this DependencyObject obj){
yield return obj;
for(int a = 0; a < VisualTreeHelper.GetChildrenCount(obj); a++){
foreach(DependencyObject child in VisualTreeHelper.GetChild(obj,a).EnumerateMeAndChildren()){
yield return child;
}
}
}
public static void UpdateBindings(this DependencyObject parent){
foreach(DependencyObject obj in parent.EnumerateMeAndChildren()){
LocalValueEnumerator enumerator = obj.GetLocalValueEnumerator();
while(enumerator.MoveNext()){
BindingExpressionBase binding = BindingOperations.GetBindingExpressionBase(obj,enumerator.Current.Property);
if (binding != null)binding.UpdateTarget();
}
}
}
}
}