< Button Content ="{Binding Path=Title}" />
* This source code was highlighted with Source Code Highlighter .
< Button Content ="{Binding Path=Height,
RelativeSource={RelativeSource Self}}" />
* This source code was highlighted with Source Code Highlighter .
public SelfBinding( string Path)
{
this .Path = Path
}
* This source code was highlighted with Source Code Highlighter .
public override object ProvideValue(IServiceProvider serviceProvider)
{
try
{
if ( string .IsNullOrEmpty(Path))
throw new ArgumentNullException( "Path" , "The Path can not be null" );
// ,
var providerValuetarget = (IProvideValueTarget)serviceProvider
.GetService( typeof (IProvideValueTarget));
// ,
DependencyObject _targetObject = (DependencyObject)providerValuetarget.TargetObject;
//
PropertyInfo _sourceProperty = _targetObject.GetType().GetProperty(Path);
//
return _sourceProperty.GetValue(_targetObject, null );
}
catch (Exception ex)
{
Debug.WriteLine(ex);
return null ;
}
}
* This source code was highlighted with Source Code Highlighter .
< Window x:Class ="for7raid.wpfExtension.Window1"
xmlns ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x ="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local ="clr-namespace:for7raid.wpfExtension"
Title ="Window1" Height ="300" Width ="300" >
< Grid >
< Button Content ="{local:SelfBinding Foreground}" />
</ Grid >
</ Window >
* This source code was highlighted with Source Code Highlighter .
// ,
if (Converter != null )
return Converter. Convert ( value , _targetProperty.PropertyType, null ,
Thread.CurrentThread.CurrentCulture);
else
return value ;
* This source code was highlighted with Source Code Highlighter .
[assembly: XmlnsDefinition( "http://schemas.microsoft.com/winfx/2006/xaml/presentation" , "for7raid.wpfExtension" )]
* This source code was highlighted with Source Code Highlighter .
< Button Content ="{Title btnKey, Default=Hello button}" ,
Visability ="{AllowedBy All sp1 sp2 sp3}" />
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/84263/