logo
down
shadow

Behaviors are not working properly inside Style Setter


Behaviors are not working properly inside Style Setter

By : Gennaro De Biase
Date : November 22 2020, 10:48 AM
like below fixes the issue This won't work because behaviors, actions or triggers are designed to be attached to a single element. When you define it inside a style's setter, it's like you are trying to associate it with multiple elements and as you have already seen, the trigger is only called when you interact with the first element with this style.
There's a simple way to fix this. Basically, you need to make sure each element that's associated with this style has a new instance of the trigger you have created. You can have all this logic wrapped inside an attached property and then your style will only need to reference this property.
code :
<Style x:Name="DisplayImage" TargetType="ScrollViewer">
    <Setter Property="VerticalScrollBarVisibility" Value="Hidden" />
    <Setter Property="HorizontalAlignment" Value="Left" />
    <Setter Property="ZoomMode" Value="Disabled" />
    <Setter Property="local:FrameworkElementEx.AttachBehaviors" Value="True" />
</Style>
public static class FrameworkElementEx
{
    public static bool GetAttachBehaviors(DependencyObject obj)
    {
        return (bool)obj.GetValue(AttachBehaviorsProperty);
    }

    public static void SetAttachBehaviors(DependencyObject obj, bool value)
    {
        obj.SetValue(AttachBehaviorsProperty, value);
    }

    public static readonly DependencyProperty AttachBehaviorsProperty =
        DependencyProperty.RegisterAttached("AttachBehaviors", typeof(bool), typeof(FrameworkElementEx), new PropertyMetadata(false, Callback));

    private static void Callback(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        var behaviors = Interaction.GetBehaviors(d);

        var eventTriggerBehavior = new EventTriggerBehavior
        {
            EventName = "DoubleTapped"
        };
        eventTriggerBehavior.Actions.Add(new ScrollViewerDoubleTap());

        behaviors.Add(eventTriggerBehavior);
    }
}


Share : facebook icon twitter icon
@dynamic property needs setter with multiple behaviors

@dynamic property needs setter with multiple behaviors


By : user2017737
Date : March 29 2020, 07:55 AM
will be helpful for those in need The solution you've tried is not exactly wrong, but should look like this:
code :
if ([uidString respondsToSelector:@selector(addObject:)]) {
    // Already an array, so don't do anything - just assign users = uidString
if ([uidString isKindOfClass[NSArray class]])
Binding a Style Setter Value properly

Binding a Style Setter Value properly


By : Dat Nguyen
Date : March 29 2020, 07:55 AM
will help you You should put you properties into a singleton, this way you can bind to and edit them from anywhere in your application.
MySingleton.cs (ViewModelBase contains an implementation of INotifyPropertyChanged)
code :
public class MySingleton: ViewModelBase
{
    private static MySingleton instance;
    private static readonly object padlock = new object();

    private FontFamily _myFont = new FontFamily();

    public static MySingleton Instance
    {
        get
        {
            lock (padlock)
            {
                if (instance == null)
                {
                    instance = new MySingleton();
                }
            }
            return instance;
        }
    }

    public FontFamily MyFont
    {
        get { return _myFont ; }
        set
        {
            _myFont = value;
            OnPropertyChanged("MyFont");
        }
    }
}
<Application ...
             xmlns:local="clr-namespace:ScrumManagementClient.ViewModel">
    <Application.Resources>
        <ResourceDictionary>
            <local:CurrentDataSingleton x:Key="Singleton"/>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="MyResourceDictionary.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>
    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

        <Style x:Key="NormalFontStyle">
            <Setter Property="Control.FontFamily" Value="{Binding Source={StaticResource  Singleton}, Path=Instance.MyFont}"/>
        </Style>

        <Style x:Key="BigFontStyle">
            <Setter Property="Control.FontFamily" Value="{Binding MyFont}"/>
            <Setter Property="Control.FontSize" Value="{Binding MyBigFontSize}"/>
        </Style>
    <ResourceDictionary/>
`Style="{StaticResource stylename}"`
MySingleton.Instance.Property = ?
Binding Value in Style Setter not working

Binding Value in Style Setter not working


By : michaelpr
Date : March 29 2020, 07:55 AM
I hope this helps you . I used the Snoop to find the binding issues. Found that the outer listbox was getting the DataContext but was not accessible to the inner listbox. I replaced the below code
code :
<Setter Property="Foreground" Value="{Binding SelectedItemForegroundColor, Converter={StaticResource stringToBrushConverter}}"/>
<Setter Property="Foreground" Value="{Binding Path=DataContext.SelectedResultItemForegroundColor, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}}"/>
UWP Binding in Style Setter not working

UWP Binding in Style Setter not working


By : wunder_awesome
Date : March 29 2020, 07:55 AM
help you fix your problem As noted in the section Migration notes on the Setter.Value property page on MSDN, UWP/Windows Runtime does not support bindings in Style Setters.
code :
public class BindingHelper
{
    public static readonly DependencyProperty GridColumnBindingPathProperty =
        DependencyProperty.RegisterAttached(
            "GridColumnBindingPath", typeof(string), typeof(BindingHelper),
            new PropertyMetadata(null, GridBindingPathPropertyChanged));

    public static readonly DependencyProperty GridRowBindingPathProperty =
        DependencyProperty.RegisterAttached(
            "GridRowBindingPath", typeof(string), typeof(BindingHelper),
            new PropertyMetadata(null, GridBindingPathPropertyChanged));

    public static string GetGridColumnBindingPath(DependencyObject obj)
    {
        return (string)obj.GetValue(GridColumnBindingPathProperty);
    }

    public static void SetGridColumnBindingPath(DependencyObject obj, string value)
    {
        obj.SetValue(GridColumnBindingPathProperty, value);
    }

    public static string GetGridRowBindingPath(DependencyObject obj)
    {
        return (string)obj.GetValue(GridRowBindingPathProperty);
    }

    public static void SetGridRowBindingPath(DependencyObject obj, string value)
    {
        obj.SetValue(GridRowBindingPathProperty, value);
    }

    private static void GridBindingPathPropertyChanged(
        DependencyObject obj, DependencyPropertyChangedEventArgs e)
    {
        var propertyPath = e.NewValue as string;

        if (propertyPath != null)
        {
            var gridProperty =
                e.Property == GridColumnBindingPathProperty
                ? Grid.ColumnProperty
                : Grid.RowProperty;

            BindingOperations.SetBinding(
                obj,
                gridProperty,
                new Binding { Path = new PropertyPath(propertyPath) });
        }
    }
}
<ItemsControl.ItemContainerStyle>
    <Style TargetType="ContentPresenter">
        <Setter Property="local:BindingHelper.GridColumnBindingPath" Value="Level"/>
        <Setter Property="local:BindingHelper.GridRowBindingPath" Value="Row"/>
    </Style>
</ItemsControl.ItemContainerStyle>
WPF style setter not working

WPF style setter not working


By : Steven Rosenberg
Date : March 29 2020, 07:55 AM
it should still fix some issue I have a custom user control that contains a combo box. I've added a ComboBoxWidth dependency property to allow developer to set width if they want. Using a style setter, I'd like to set the widths for all these combo boxes to the same value on another user control for size consistency. But, it is not working. It works if I set the size separately on each control. When the size is specified in the style setter, it is ignored. If I change the Property string from "ComboBoxWidth" to "Width", the entire width of all the controls are changed. So, it looks like the style formatting is correct. Am I missing something? This is the first time I've tried to apply a style to my own custom dependency property. , A so-called "local value" of a dependency property, like
code :
this.ComboBoxWidth = 175.0;
<Setter Property="ComboBoxWidth" Value="400"/>
public class AngleUserControl : ...
{
    static AngleUserControl()
    {
        ComboBoxWidthProperty.OverrideMetadata(
            typeof(AngleUserControl),
            new PropertyMetadata(175d));
    }
}
Related Posts Related Posts :
  • I am trying to do a while loop with a string conditional statement in C#
  • C# 'Cannot access a disposed object. Object name: 'SslStream'.'
  • How to make Gecko use seperate CookieContainer per instance?
  • C# Advanced form "please wait"
  • Send and Receive data C# using network stream
  • How to discover that appsettings changed in C#?
  • Check what needs full trust
  • What is the execution order of an MVC Razor view/layout
  • Table designer (Entity Framework) is too resource intense
  • How to clean up an exception string so it can be displayed via Javascript Alert?
  • Configuring Amazon SES Feedback Notifications via Amazon SNS in ASP.NET MVC (C#)
  • C# api responce and request
  • Dynamodb putitem function not working properly
  • theme in windows phone(light or dark) using c#
  • Backup attached database file(.mdf) using c# and SQL Server
  • What is 'TextFile' and where it is uses in WPF project
  • Using same alias for multiple namespaces
  • how to move mails into separate folders
  • Multithreaded Uploader
  • Memory fragmentation?
  • C# correct exception handling
  • "Could not open macro storage" when accessing using file on another machine
  • How to access other directories of hosted server
  • C# Jagged Array check if value exists/true
  • Why can't I type Clone() properly?
  • exception on accessing dictionary from list
  • Getting the immediate response from server without waiting to 200 message
  • Why am I getting exception Directory Is Not empty?
  • Could not load file or assembly 'CefSharp.dll' or one of its dependencies
  • Sending Email By Using C# in unity3D?
  • Correct usage of await async in webapi
  • Program update code issue
  • Marshal.Copy attempted to read or write protected memory At Random Times
  • Restrict Type variable to specific class or subclass
  • Horizontal text alignment in a PdfPCell
  • C# crashing with Form.show() command, ObjectDisposedException - Deeper look / explanation please
  • Will the result of a LINQ query always be guaranteed to be in the correct order?
  • "Could not find default endpoint element that references contract"
  • Umbraco Request.QueryString is null if it's the first time the page is loaded
  • Error inconsistent accessibility method C#
  • How to program Intel Xeon Phi with C#?
  • remove nested element using regular expression
  • Is there a C# alternative to Java's vararg parameters?
  • Clear particular column values in DataTable
  • how to add event handler to programatically created checkboxes
  • Cannot apply indexing with [] to an expression of type 'System.Collections.Specialized.NameValueCollection'
  • Check for key in pre-existing dictionary in case insensitive manner
  • How to remove year from datetime object?
  • Accessing Settings in different ways
  • "This project is empty" error in Sonarqube
  • How to create reusable icon menu in Xamarin
  • Value Cannot be null in Ado.Net connectivity
  • Adding a custom/dynamic attribute when using XSD.exe
  • How to convert object to correct type
  • Automatically sign out from Forms Authentication in ASP.NET when browser is closed
  • Can a WCF service support both Buffered and Streamed transfer modes?
  • Verify a CA Certificate with a public key in C#
  • How to invoke a Web Service that requires the "patch" verb using the C# WebClient wrapper?
  • Proper way a implementing property based on generic type
  • Closing a form that is created in another thread
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org