c# - Binding const member in code behind from xaml in WPF -


Is there a good way to bind the property in a console value in Codebehind?

When I am a combo box, I usually do this in XML and the following code:

XAM:

   & Lt; ComboBoxItem Content = "Bar" UID = "Bar" /> & Lt; / ComboBox & gt;   

Codebehind:

  combo box item = cbBuz.GetSelectedItem (); Switch (item. Uid) {case "foo": ... break; The case "bar": ... break; }   

The way I chose this method is following it:

  • For the localization purpose, not use content string to determine It should be done which items are selected during the saving and loading the last selected item.
  • For simplicity, XAM and code-back should be connected to the internal identifier (in this case, the UID). Therefore, XML and code-behind can be created separately.

    However, maintenance-wise, the internal identifier should be defined in a place like this:

      // id public key string ID_foo = "foo "; Public const string ID_bar = "bar"; ... // switch (item. Uid) {case ID_foo: ... break; Case ID_bar: ... break; }   

    The problem seems to be that the property can not const, so there is no way to bind ID_foo and ID_bar to comboboxIITM like this:

     < Code> // if it has ID_foo and ID_bar properties, it will work. & Lt; Combo box name = "cbBuz" & gt; & Lt; Combobox item content = "foo" uid = "{binding id_fu}" is isolated = "true" /> & Lt; Combobox item content = "bar" uid = "{binding id_bar}" /> & Lt; / ComboBox & gt;   

    So, I have to know how to solve this issue. Or, there is no better way to implement it, it would also be good.

    Best,

    You will be better using, like:

      UID = "{x: static locale: yourclass.ID_foo}"   

    Where local one xmlns is for nickname # Your class name Location More info Can be found.

    The problem with using bindings is that you are adding too much overhead for something that will never change. Binding will try to monitor your property, as well as using bindings with a non-dependent property on an object that does not implement the inotipopetric change.

Comments