Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
I

iwangoll

@iwangoll
About
Posts
3
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • DependencyProperty fires only in ViewModel.ctor
    I iwangoll

    Dear Richard, many thanks for your help. Now it works. And I think I understand the functionality of DependencyProperty much better now. And sorry for the GitHub & 7z. I'm very new there.

    WPF wpf debugging help question

  • DependencyProperty fires only in ViewModel.ctor
    I iwangoll

    Thank you for your answer. I have changed my test project and adapted the original message. 1. removed all Debug.Writeline in TestControl 2. in ViewModel

    set { SetProperty(ref _testInfoView, value); }

    3. Added a button BtnShow to see in it's Click in xaml.cs the content of TestInfo property In the original post under "After starting the app" I'd explained what I've done. But the ViewModel-command didn't change the property. I've added the code to GitHub - iwangoll/TestBinding: ViewModel-command didn't change the DependencyProperty.[^]

    WPF wpf debugging help question

  • DependencyProperty fires only in ViewModel.ctor
    I iwangoll

    Hello, I'd tried to reduce the problem. I've this UserControl

    public class TestControl : Label
    {
    public static readonly DependencyProperty dependencyPropertyTestInfo =
    DependencyProperty.Register("TestInfo", typeof(string), typeof(TestControl),
    new PropertyMetadata("", new PropertyChangedCallback(ChangeTestInfo)));

    public string TestInfo
    {
        get => (string)GetValue(dependencyPropertyTestInfo);
        set => SetValue(dependencyPropertyTestInfo, value);
    }
    private static void ChangeTestInfo(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        var testControl = (TestControl)d;
        testControl.TestInfo = (string)e.NewValue;
    }
    

    }

    This is the essential part of MainWindow.xaml:

    Its bounded in MainWindow.xaml.cs to DataContext with this ViewModel:

    public class MainWindowViewModel : BindableBase
    {
    private int counter;
    private string _testInfoView;
    public string TestInfoView
    {
    get { return _testInfoView; }
    set { SetProperty(ref _testInfoView, value); }
    }
    public DelegateCommand NewTestInfoCommand { get; }
    public MainWindowViewModel()
    {
    NewTestInfoCommand = new DelegateCommand(OnNewTestInfoCommand);
    TestInfoView = "Info from ctor";
    }
    private void OnNewTestInfoCommand()
    {
    string newInfo = $"Info No. {++counter}";
    Debug.WriteLine($"{MethodBase.GetCurrentMethod().Name}: {nameof(TestInfoView)}=«{TestInfoView}» -> «{newInfo}»");
    TestInfoView = newInfo;
    }
    }

    I've added a "Debug.WriteLine" in MainWindow.xaml.cs

    private void BtnShow_Click(object sender, RoutedEventArgs e)
    {
    Debug.WriteLine($"{MethodBase.GetCurrentMethod().Name}: {nameof(tct.TestInfo)}={tct.TestInfo}");
    }

    After starting the app 1. I've clicked "BtnShow" this is the debug-info: BtnShow_Click: TestInfo=Info from ctor 2. I've clicked "BtnNewTestInfo" this is the debug-info: OnNewTestInfoCommand: TestInfoView=«Info from ctor» -> «Info No. 1» 3. I've clicked "BtnShow" this is the debug-info: BtnShow_Click: TestInfo=Info from ctor Now my question is: why View

    WPF wpf debugging help question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups