Alex141 / CalcBinding

Advanced WPF Binding which supports expressions in Path property and other features

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possible enhancement

maurosampietro opened this issue · comments

Hi,
I understand this library is called CalBinding and so this may be out of scope but
it would be nice if bindings could parse complex c# expression so it could substitute some trivial converter class. Example:

public class OverlayVisibleConverter : BaseConverter, IMultiValueConverter
{
    public object Convert( object[] values, Type targetType, object parameter, CultureInfo culture )
    {
        bool isKeyboardFocusWithin = (bool)values[ 0 ];
        var passwordBox = (PasswordBox)values[2];

        bool visibile = !isKeyboardFocusWithin && String.IsNullOrEmpty( passwordBox.Password );
        return visibile ? Visibility.Visible : Visibility.Collapsed;
    }  
}


<Label.Visibility>
        <MultiBinding Converter="{StaticResource overlayLabelVisibilityConverter }">
                   <Binding ElementName="passwordBox" Path="IsKeyboardFocusWithin" />
                   <Binding ElementName="passwordBox" Path="SecurePassword" />
                   <Binding ElementName="passwordBox" />
        </MultiBinding>
</Label.Visibility>

Would be nice it it could become something like this, removing the converter class:

  <Label.Visibility>
            <MultiBinding Converter="**{calcBinding:Binding '!passwordBox.IsKeyboardFoucsWithin and passwordBox.SecurePassword'** }">
                  <Binding ElementName="passwordBox" Path="IsKeyboardFocusWithin" />
                  <Binding ElementName="passwordBox" Path="SecurePassword" />
                  <Binding ElementName="passwordBox" />
             </MultiBinding>
 </Label.Visibility>

This probably involve the management of ElementNames.
Do you think it is feasible? I can help out if this is considered helpful.

Thank you.

Hi,

CalcBinding:Binding in most cases extends or repeats standart Binding behavior, so to solve your problem, you just need to use ElementName property like this:
<Label Visibility="{c:Binding Path='!IsKeyboardFocusWithin and SecurePassword' ElementName=passwordBox}"/>

That expression will be automaticaly converted into MultiBinding that you wrote higher
:)

Good! But what if i need to target multiple element names ?

Mauro Sampietro
Inviato da iPhone

Il giorno 27 lug 2016, alle ore 23:43, Alex141 notifications@github.com ha scritto:

Hi,

CalcBinding:Binding in most cases extends or repeats standart Binding behavior, so to solve your problem, you just need to use ElementName property like this:
`

That expression will be automaticaly converted into MultiBinding that you wrote higher
:)


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.

You know, this is not one task but this is a whole class of tasks - setting "Source" for each target property in binding instead of a whole binding expression. That class includes problems of setting "ElementName", "RelativeSource", "static classes" and others.
Calbinding was originally developed with one idea - simplest way for writing inline binding expressions. So, if you need more powerfull library, take a look at QuickConverter: https://quickconverter.codeplex.com/ . It allows you to write more powerful but less readable expressions :)

Good! But what if i need ti target multiple element names ?