Click here to Skip to main content
15,884,353 members
Home / Discussions / WPF
   

WPF

 
QuestionCan we add animation to WPF just like we have SHAPE animation in powerpoint? Pin
User-86216959-Jul-20 23:57
User-86216959-Jul-20 23:57 
QuestionVertical text in WPF grid Pin
kalberts6-Jul-20 8:54
kalberts6-Jul-20 8:54 
AnswerRe: Vertical text in WPF grid Pin
Gerry Schmitz6-Jul-20 12:10
mveGerry Schmitz6-Jul-20 12:10 
AnswerRe: Vertical text in WPF grid Pin
Richard Deeming6-Jul-20 23:43
mveRichard Deeming6-Jul-20 23:43 
GeneralRe: Vertical text in WPF grid Pin
kalberts7-Jul-20 5:03
kalberts7-Jul-20 5:03 
QuestionBehavior/DP Question Pin
Kevin Marois22-Jun-20 8:27
professionalKevin Marois22-Jun-20 8:27 
AnswerRe: Behavior/DP Question Pin
Richard Deeming23-Jun-20 4:44
mveRichard Deeming23-Jun-20 4:44 
GeneralRe: Behavior/DP Question Pin
Kevin Marois1-Jul-20 8:30
professionalKevin Marois1-Jul-20 8:30 
Ok, so I implemented your changes and the GetAllowEnable(sender) gets called fine. However, overall things still don't work right. Let me explain...

This is all in a small WPF test app. On the window I have a TextBox, and a ToggleButton called Enabled. When the Toggle is clicked, I set a property in the code behind called AreFieldsEnabled to True. This property is bound on the TextBox to the SecurityBehavior's AllowEnable DP:
<TextBox Grid.Row="2" 
            Grid.Column="1"
            Text="{Binding EmployeeName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
            Height="32"
            Width="250"
            local:SecurityBehavior.AllowEnable="{Binding AreFieldsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
            local:SecurityBehavior.SecurityTags="can_add_employees|can_edit_employees" 
            HorizontalAlignment="Left"
            VerticalAlignment="Top"
            Margin="5"/>


The problem is that the SecurityTags DP gets called first, which calls GetAllowEnable, which return False by default because AllowEnable hasn't yet been set to True (using the ToggleButton). Later, when I toggle the button and set AreFieldsEnabled to True, the SecurityTags property is never called again, so nothing is enabled. Here's all the code:

Behavior
public static class SecurityBehavior
{
    private static readonly char[] TagSeparators = { '|' };
    #region Allow Enable
    public static readonly DependencyProperty AllowEnableProperty =
                                DependencyProperty.RegisterAttached("AllowEnable",
                                typeof(bool),
                                typeof(SecurityBehavior),
                                new PropertyMetadata(false, OnAllowEnableChanged));
    public static bool GetAllowEnable(DependencyObject obj)
    {
        return (bool)obj.GetValue(AllowEnableProperty);
    }
    public static void SetAllowEnable(DependencyObject obj, bool value)
    {
        obj.SetValue(AllowEnableProperty, value);
    }
    private static void OnAllowEnableChanged(object sender, DependencyPropertyChangedEventArgs e)
    {
        FrameworkElement element = (FrameworkElement)sender;
    }
    #endregion
    #region Security Tags
    public static readonly DependencyProperty SecurityTagsProperty =
            DependencyProperty.RegisterAttached("SecurityTags",
            typeof(string), typeof(SecurityBehavior),
            new PropertyMetadata("", OnSecurityChanged));
    public static string GetSecurityTags(DependencyObject obj)
    {
        return (string)obj.GetValue(SecurityTagsProperty);
    }
    public static void SetSecurityTags(DependencyObject obj, string value)
    {
        obj.SetValue(SecurityTagsProperty, value);
    }
    private static void OnSecurityChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
    {
        bool canEnable = GetAllowEnable(sender); //<=============== Returns FALSE by default
        if (canEnable)
        {
            string[] tags = GetSecurityTags(sender).Split(TagSeparators, StringSplitOptions.RemoveEmptyEntries);
            foreach (string tag in tags)
            {
                canEnable &= SecurityService.HasRights(tag);
            }
        }
        var element = (UIElement)sender;
        element.IsEnabled = canEnable;
    }
    #endregion
}
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.

GeneralRe: Behavior/DP Question Pin
Richard Deeming1-Jul-20 23:32
mveRichard Deeming1-Jul-20 23:32 
GeneralRe: Behavior/DP Question Pin
Kevin Marois2-Jul-20 8:49
professionalKevin Marois2-Jul-20 8:49 
Question2 xaml windows question Pin
Michele Smith26-May-20 7:10
Michele Smith26-May-20 7:10 
AnswerRe: 2 xaml windows question Pin
#realJSOP26-May-20 7:43
mve#realJSOP26-May-20 7:43 
QuestionCreate DataGrid From List<T> With Properties As Columns Pin
Kevin Marois18-May-20 7:14
professionalKevin Marois18-May-20 7:14 
AnswerRe: Create DataGrid From List<T> With Properties As Columns Pin
Richard Deeming18-May-20 8:47
mveRichard Deeming18-May-20 8:47 
GeneralRe: Create DataGrid From List<T> With Properties As Columns Pin
Kevin Marois18-May-20 8:52
professionalKevin Marois18-May-20 8:52 
QuestionWPF ListBox Pin
michaelbarb7-May-20 10:03
michaelbarb7-May-20 10:03 
AnswerRe: WPF ListBox Pin
Richard Deeming10-May-20 21:52
mveRichard Deeming10-May-20 21:52 
GeneralRe: WPF ListBox Pin
michaelbarb11-May-20 19:11
michaelbarb11-May-20 19:11 
GeneralRe: WPF ListBox Pin
Mycroft Holmes11-May-20 21:33
professionalMycroft Holmes11-May-20 21:33 
AnswerRe: WPF ListBox Pin
Gerry Schmitz11-May-20 12:42
mveGerry Schmitz11-May-20 12:42 
QuestionDesign Question Pin
Kevin Marois18-Apr-20 15:26
professionalKevin Marois18-Apr-20 15:26 
AnswerRe: Design Question Pin
Mycroft Holmes19-Apr-20 12:20
professionalMycroft Holmes19-Apr-20 12:20 
GeneralRe: Design Question Pin
Kevin Marois19-Apr-20 14:09
professionalKevin Marois19-Apr-20 14:09 
GeneralRe: Design Question Pin
Mycroft Holmes20-Apr-20 12:20
professionalMycroft Holmes20-Apr-20 12:20 
QuestionMVVM: DataGrid Cell BeginEdit Pin
Kevin Marois13-Apr-20 9:10
professionalKevin Marois13-Apr-20 9:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.