Click here to Skip to main content
15,867,686 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: Custom drawing ToggleButton when checked Pin
Gerry Schmitz17-Oct-22 10:11
mveGerry Schmitz17-Oct-22 10:11 
GeneralRe: Custom drawing ToggleButton when checked Pin
Maximilien24-Oct-22 2:48
Maximilien24-Oct-22 2:48 
QuestionReferencing DrawingImage in a binding. Pin
Maximilien5-Oct-22 2:24
Maximilien5-Oct-22 2:24 
AnswerRe: Referencing DrawingImage in a binding. Pin
Richard Deeming5-Oct-22 5:29
mveRichard Deeming5-Oct-22 5:29 
GeneralRe: Referencing DrawingImage in a binding. Pin
Maximilien5-Oct-22 7:14
Maximilien5-Oct-22 7:14 
GeneralRe: Referencing DrawingImage in a binding. Pin
Maximilien5-Oct-22 7:55
Maximilien5-Oct-22 7:55 
QuestionDesign Question Pin
Kevin Marois2-Oct-22 11:13
professionalKevin Marois2-Oct-22 11:13 
AnswerRe: Design Question Pin
Gerry Schmitz2-Oct-22 15:47
mveGerry Schmitz2-Oct-22 15:47 
QuestionLooking for a WPF control. Pin
Maximilien22-Sep-22 8:40
Maximilien22-Sep-22 8:40 
AnswerRe: Looking for a WPF control. Pin
Richard Deeming22-Sep-22 21:39
mveRichard Deeming22-Sep-22 21:39 
GeneralRe: Looking for a WPF control. Pin
Maximilien23-Sep-22 1:33
Maximilien23-Sep-22 1:33 
GeneralRe: Looking for a WPF control. Pin
Maximilien23-Sep-22 1:54
Maximilien23-Sep-22 1:54 
QuestionWeird behavior with contextual menu not rendering properly. Pin
Maximilien21-Sep-22 7:00
Maximilien21-Sep-22 7:00 
AnswerRe: Weird behavior with contextual menu not rendering properly. Pin
Richard Deeming21-Sep-22 21:36
mveRichard Deeming21-Sep-22 21:36 
GeneralRe: Weird behavior with contextual menu not rendering properly. Pin
Maximilien22-Sep-22 8:22
Maximilien22-Sep-22 8:22 
QuestionConversion to .Net Core Issues Pin
Kevin Marois19-Sep-22 6:39
professionalKevin Marois19-Sep-22 6:39 
AnswerRe: Conversion to .Net Core Issues Pin
Richard Deeming19-Sep-22 21:20
mveRichard Deeming19-Sep-22 21:20 
GeneralRe: Conversion to .Net Core Issues Pin
Kevin Marois20-Sep-22 7:10
professionalKevin Marois20-Sep-22 7:10 
GeneralRe: Conversion to .Net Core Issues Pin
Kevin Marois22-Sep-22 5:57
professionalKevin Marois22-Sep-22 5:57 
GeneralRe: Conversion to .Net Core Issues Pin
Richard Deeming22-Sep-22 21:38
mveRichard Deeming22-Sep-22 21:38 
QuestionUsing Dependency Property's to Affect Non WPF Property's Pin
Marc Jeeves1-Sep-22 10:52
Marc Jeeves1-Sep-22 10: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 22:11
mveRichard Deeming1-Sep-22 22:11 
GeneralRe: Using Dependency Property's to Affect Non WPF Property's Pin
Marc Jeeves2-Sep-22 4:11
Marc Jeeves2-Sep-22 4:11 
GeneralRe: Using Dependency Property's to Affect Non WPF Property's Pin
Richard MacCutchan3-Sep-22 21:01
mveRichard MacCutchan3-Sep-22 21:01 
GeneralRe: Using Dependency Property's to Affect Non WPF Property's Pin
mjeeves3-Sep-22 8:58
mjeeves3-Sep-22 8:58 

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.