Click here to Skip to main content
15,507,526 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: Weird behavior with contextual menu not rendering properly. Pin
Richard Deeming21-Sep-22 22:36
mveRichard Deeming21-Sep-22 22:36 
GeneralRe: Weird behavior with contextual menu not rendering properly. Pin
Maximilien22-Sep-22 9:22
Maximilien22-Sep-22 9:22 
QuestionConversion to .Net Core Issues Pin
Kevin Marois19-Sep-22 7:39
professionalKevin Marois19-Sep-22 7:39 
AnswerRe: Conversion to .Net Core Issues Pin
Richard Deeming19-Sep-22 22:20
mveRichard Deeming19-Sep-22 22:20 
GeneralRe: Conversion to .Net Core Issues Pin
Kevin Marois20-Sep-22 8:10
professionalKevin Marois20-Sep-22 8:10 
GeneralRe: Conversion to .Net Core Issues Pin
Kevin Marois22-Sep-22 6:57
professionalKevin Marois22-Sep-22 6:57 
GeneralRe: Conversion to .Net Core Issues Pin
Richard Deeming22-Sep-22 22:38
mveRichard Deeming22-Sep-22 22:38 
QuestionUsing Dependency Property's to Affect Non WPF Property's Pin
Marc Jeeves1-Sep-22 11:52
Marc Jeeves1-Sep-22 11:52 
Im building a Ticker User Control and my dependency property's that directly bind to the XAML which works great, but I have some dependency property's that drive the Beating Internal Class which controls the motion of the three bars.

When I change these in the viewmodel they have no affect on the Internal Class Property's so I cant change the speed or starting length and so on.

I though if I passed in the Code behind class into the Beating internal class I could do it this way, but i almost need an onPropertychanged event to force the update.

thanks

Madaxe


XAML User Control
C#
<UserControl x:Class="DES.CATIAV6.ClearanceContactAndClashManager.UI.Controls.WaitTicker_Control"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:DES.CATIAV6.ClearanceContactAndClashManager.UI.Controls"
             mc:Ignorable="d" 
             Background="Transparent" 
             Height="70" Width="60"
             Name="WaitTickerControl">
    <Grid Name="WaitTickerMainGrid" Visibility="{Binding Path=ControlHideShow,ElementName=WaitTickerControl, FallbackValue=Hidden}">
        <Border Name="Pulse1" 
                CornerRadius="{Binding Path=ControlCornerRadius1,ElementName=WaitTickerControl,FallbackValue=10}"
                Height="{Binding Path=PulseHeight1,ElementName=WaitTickerControl,FallbackValue=50}"
                Width="{Binding Path=PulseWidth1,ElementName=WaitTickerControl,FallbackValue=10}"
                Margin="10,10,0,0"
                Background="{Binding Path=ControlBackground1,ElementName=WaitTickerControl,FallbackValue=#4287f5}" 
                HorizontalAlignment="Left" VerticalAlignment="Top"/>

        <Border Name="Pulse2"
                CornerRadius="{Binding Path=ControlCornerRadius2,ElementName=WaitTickerControl,FallbackValue=10}"
                Height="{Binding Path=PulseHeight2,ElementName=WaitTickerControl,FallbackValue=50}"
                Width="{Binding Path=PulseWidth2,ElementName=WaitTickerControl,FallbackValue=10}"
                Margin="25,10,0,0"
                Background="{Binding Path=ControlBackground2,ElementName=WaitTickerControl,FallbackValue=#4287f5}" 
                HorizontalAlignment="Left" VerticalAlignment="Top"/>

        <Border Name="Pulse3"
                CornerRadius="{Binding Path=ControlCornerRadius3,ElementName=WaitTickerControl,FallbackValue=10}"
                Height="{Binding Path=PulseHeight3,ElementName=WaitTickerControl,FallbackValue=50}"
                Width="{Binding Path=PulseWidth3,ElementName=WaitTickerControl,FallbackValue=10}"
                Margin="40,10,0,0"
                Background="{Binding Path=ControlBackground3,ElementName=WaitTickerControl,FallbackValue=#4287f5}" 
                HorizontalAlignment="Left" VerticalAlignment="Top"/>
    </Grid>

</UserControl>


C# Code Behind

C#
public partial class WaitTicker_Control : UserControl, INotifyPropertyChanged
    {
        #region "INotifyPropertyChanged"
        public event PropertyChangedEventHandler? PropertyChanged;
        protected void OnPropertyChanged([CallerMemberName] string? propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        private Beating? _Timer1 = null;
        private Beating? _Timer2 = null;
        private Beating? _Timer3 = null;

        public int PulseCurrentValue1
        {
            get { return (int)GetValue(PulseCurrentValue1Property); }
            set { SetValue(PulseCurrentValue1Property, value); }
        }
        public static readonly DependencyProperty PulseCurrentValue1Property =
            DependencyProperty.Register("PulseCurrentValue1", typeof(int), typeof(WaitTicker_Control), 
                new PropertyMetadata(5));
        public int PulseCurrentValue2
        {
            get { return (int)GetValue(PulseCurrentValue2Property); }
            set { SetValue(PulseCurrentValue2Property, value); }
        }
        public static readonly DependencyProperty PulseCurrentValue2Property =
            DependencyProperty.Register("PulseCurrentValue2", typeof(int), typeof(WaitTicker_Control), 
                new PropertyMetadata(20));
        public int PulseCurrentValue3
        {
            get { return (int)GetValue(PulseCurrentValue3Property); }
            set { SetValue(PulseCurrentValue3Property, value); }
        }
        public static readonly DependencyProperty PulseCurrentValue3Property =
            DependencyProperty.Register("PulseCurrentValue3", typeof(int), typeof(WaitTicker_Control), 
                new PropertyMetadata(40));
        public int PulseMaxValue
        {
            get { return (int)GetValue(PulseMaxValueProperty); }
            set { SetValue(PulseMaxValueProperty, value); }
        }
        public static readonly DependencyProperty PulseMaxValueProperty =
            DependencyProperty.Register("PulseMaxValue", typeof(int), typeof(WaitTicker_Control), 
                new PropertyMetadata(50));
        public int PulseMinValue
        {
            get { return (int)GetValue(PulseMinValueProperty); }
            set { SetValue(PulseMinValueProperty, value); }
        }
        public static readonly DependencyProperty PulseMinValueProperty =
            DependencyProperty.Register("PulseMinValue", typeof(int), typeof(WaitTicker_Control), 
                new PropertyMetadata(10));
        public int PulseIncrementValue
        {
            get { return (int)GetValue(PulseIncrementValueProperty); }
            set { SetValue(PulseIncrementValueProperty, value); }
        }
        public static readonly DependencyProperty PulseIncrementValueProperty =
            DependencyProperty.Register("PulseIncrementValue", typeof(int), typeof(WaitTicker_Control), 
                new PropertyMetadata(1));

        public double PulseSpeedValue
        {
            get { return (double)GetValue(PulseSpeedValueProperty); }
            set { SetValue(PulseSpeedValueProperty, value); }
        }
        public static readonly DependencyProperty PulseSpeedValueProperty =
            DependencyProperty.Register("PulseSpeedValue", typeof(double), typeof(WaitTicker_Control), 
                new PropertyMetadata(0.01));

        #endregion

        public WaitTicker_Control()
        {
                InitializeComponent();
                _Timer1 = new Beating(Pulse1, this, PulseCurrentValue1, "Pulse1");
                _Timer2 = new Beating(Pulse2, this, PulseCurrentValue2, "Pulse2");
                _Timer3 = new Beating(Pulse3, this, PulseCurrentValue3, "Pulse3");
        }
    }


internal Class Code Behind

C#
internal class Beating
{
    private static Timer? _BeatingTimer=null;
    private Dispatcher? _Dispatcher=null;

    private WaitTicker_Control _waitTicker_Control;
    private Border? _pulse { get; set; } = null;
    private bool _Direction = false;

    public string BeatName { get; set; } = string.Empty;
    public int InitialValue { get; set; } = 50;
    public int Increment { get; set; } = 1;
    public int MinValue { get; set; } = 0;
    public int MaxValue { get; set; } = 100;


    public Beating(
        Border pulse,
        WaitTicker_Control waitTicker_Control,
        int initialValue,
        string iBeatName)
    {
        _waitTicker_Control = waitTicker_Control;
        _pulse = pulse;

        MinValue = waitTicker_Control.PulseMinValue;
        MaxValue = waitTicker_Control.PulseMaxValue;
        InitialValue = initialValue;
        Increment = waitTicker_Control.PulseIncrementValue;
        BeatName = iBeatName;

        _Dispatcher = Dispatcher.CurrentDispatcher;

        Beating._BeatingTimer = new Timer();
        Beating._BeatingTimer.Interval = waitTicker_Control.PulseSpeedValue;

        Beating._BeatingTimer.Elapsed += OnTimedEvent;
        Beating._BeatingTimer.AutoReset = true;
        Beating._BeatingTimer.Enabled = true;
    }

    public void StartTimer()
    {
        Beating._BeatingTimer?.Start();
    }

    public void StopTimer()
    {
        Beating._BeatingTimer?.Stop();
    }
    private void OnTimedEvent(Object source, ElapsedEventArgs e)
    {
        try
        {
            if (this._Direction == false)
            {
                this.InitialValue = this.InitialValue - this.Increment;
                if (this.InitialValue < this.MinValue)
                    this._Direction = true;
            }
            else
            {
                this.InitialValue = this.InitialValue + this.Increment;
                if (this.InitialValue > this.MaxValue)
                    this._Direction = false;
            }
            if (this._pulse != null)
            {
                this._Dispatcher?.Invoke(new Action(() => { this._pulse.Height = this.InitialValue; }));
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }
}

AnswerRe: Using Dependency Property's to Affect Non WPF Property's Pin
Richard Deeming1-Sep-22 23:11
mveRichard Deeming1-Sep-22 23:11 
GeneralRe: Using Dependency Property's to Affect Non WPF Property's Pin
Marc Jeeves2-Sep-22 5:11
Marc Jeeves2-Sep-22 5:11 
GeneralRe: Using Dependency Property's to Affect Non WPF Property's Pin
Richard MacCutchan3-Sep-22 22:01
mveRichard MacCutchan3-Sep-22 22:01 
GeneralRe: Using Dependency Property's to Affect Non WPF Property's Pin
mjeeves3-Sep-22 9:58
mjeeves3-Sep-22 9:58 
GeneralRe: Using Dependency Property's to Affect Non WPF Property's Pin
Gerry Schmitz4-Sep-22 9:57
mveGerry Schmitz4-Sep-22 9:57 
GeneralRe: Using Dependency Property's to Affect Non WPF Property's Pin
Richard Deeming5-Sep-22 22:11
mveRichard Deeming5-Sep-22 22:11 
GeneralRe: Using Dependency Property's to Affect Non WPF Property's Pin
Gerry Schmitz6-Sep-22 6:34
mveGerry Schmitz6-Sep-22 6:34 
GeneralRe: Using Dependency Property's to Affect Non WPF Property's Pin
Marc Jeeves6-Sep-22 11:05
Marc Jeeves6-Sep-22 11:05 
GeneralRe: Using Dependency Property's to Affect Non WPF Property's Pin
Gerry Schmitz6-Sep-22 14:19
mveGerry Schmitz6-Sep-22 14:19 
QuestionCan Not Bin to Dependency Property in Custom Control Pin
Marc Jeeves1-Sep-22 7:26
Marc Jeeves1-Sep-22 7:26 
AnswerRe: Can Not Bin to Dependency Property in Custom Control Pin
Richard Deeming1-Sep-22 7:35
mveRichard Deeming1-Sep-22 7:35 
GeneralRe: Can Not Bin to Dependency Property in Custom Control Pin
Marc Jeeves1-Sep-22 7:47
Marc Jeeves1-Sep-22 7:47 
QuestionWhat is the most common MVVM framework used today? Pin
Code4Ever21-Jul-22 8:26
Code4Ever21-Jul-22 8:26 
AnswerRe: What is the most common MVVM framework used today? Pin
Pete O'Hanlon21-Jul-22 22:21
mvaPete O'Hanlon21-Jul-22 22:21 
AnswerRe: What is the most common MVVM framework used today? Pin
Richard Deeming21-Jul-22 22:22
mveRichard Deeming21-Jul-22 22:22 
AnswerRe: What is the most common MVVM framework used today? Pin
Gerry Schmitz22-Jul-22 6:10
mveGerry Schmitz22-Jul-22 6:10 
GeneralRe: What is the most common MVVM framework used today? Pin
Pete O'Hanlon24-Jul-22 12:32
mvaPete O'Hanlon24-Jul-22 12:32 

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.