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
  1. Home
  2. General Programming
  3. WPF
  4. Got some problem with wpf multibinding

Got some problem with wpf multibinding

Scheduled Pinned Locked Moved WPF
wpfcsharpwcfhelptutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Eric Vonjacson
    wrote on last edited by
    #1

    Hi, I have some problem withe multi binding in wpf: 1) In the widnow cs file, I define a property like this:

    private ObservableCollection<string> colltest = new ObservableCollection<string>();
    public ObservableCollection<string> Coll
    {
      get
      {
        return this.colltest;
      }
    }
    
    1. In the xaml file define a multi binding to the "togglebutton".

      <ToggleButton Tag="dd" Content="TT" Width="50" Height="50">
      <ToggleButton.IsChecked>
      <MultiBinding Mode="OneWay" Converter="{x:Static app:SimpleConverter.Instance}">
      <Binding Mode="OneWay" RelativeSource="{RelativeSource Mode=FindAncestor,AncestorType={x:Type app:Window1}}"
      Path="Coll" />
      <Binding Mode="OneWay" RelativeSource="{RelativeSource Mode=Self}" Path="Tag" />
      </MultiBinding>
      </ToggleButton.IsChecked>
      </ToggleButton>

    2. and the covnert function of the converter is like this:

      public object Convert(object[] value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
      bool bflag = false;

      if (value[0] == DependencyProperty.UnsetValue || value[0] == null||
      value[1] == DependencyProperty.UnsetValue ||
      value[1] == null)
      return bflag;

      ObservableCollection<string> v1 = value[0] as ObservableCollection<string>;
      string v2 = (string)value[1];

      if (v1 != null)
      {
      bflag = v1.Contains(v2);
      }

      return bflag;
      }

    It's working after the window is loadded. But however, after I add some new string to the collection "colltest", the togglebutton's "IsChecked" is not updated automatically. I want it working in this way: If any changes are made to the collection "colltest". The togglebutton's "IsChecked" could update accordingly. So how to resolve this problem? thanks.

    M I 2 Replies Last reply
    0
    • E Eric Vonjacson

      Hi, I have some problem withe multi binding in wpf: 1) In the widnow cs file, I define a property like this:

      private ObservableCollection<string> colltest = new ObservableCollection<string>();
      public ObservableCollection<string> Coll
      {
        get
        {
          return this.colltest;
        }
      }
      
      1. In the xaml file define a multi binding to the "togglebutton".

        <ToggleButton Tag="dd" Content="TT" Width="50" Height="50">
        <ToggleButton.IsChecked>
        <MultiBinding Mode="OneWay" Converter="{x:Static app:SimpleConverter.Instance}">
        <Binding Mode="OneWay" RelativeSource="{RelativeSource Mode=FindAncestor,AncestorType={x:Type app:Window1}}"
        Path="Coll" />
        <Binding Mode="OneWay" RelativeSource="{RelativeSource Mode=Self}" Path="Tag" />
        </MultiBinding>
        </ToggleButton.IsChecked>
        </ToggleButton>

      2. and the covnert function of the converter is like this:

        public object Convert(object[] value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
        bool bflag = false;

        if (value[0] == DependencyProperty.UnsetValue || value[0] == null||
        value[1] == DependencyProperty.UnsetValue ||
        value[1] == null)
        return bflag;

        ObservableCollection<string> v1 = value[0] as ObservableCollection<string>;
        string v2 = (string)value[1];

        if (v1 != null)
        {
        bflag = v1.Contains(v2);
        }

        return bflag;
        }

      It's working after the window is loadded. But however, after I add some new string to the collection "colltest", the togglebutton's "IsChecked" is not updated automatically. I want it working in this way: If any changes are made to the collection "colltest". The togglebutton's "IsChecked" could update accordingly. So how to resolve this problem? thanks.

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      Eric Vonjacson wrote:

      If any changes are made to the collection "colltest". The togglebutton's "IsChecked" could update accordingly.

      What kind of changes? ObservableCollection notifies about changes to the collection, but if you want notifications on changes to items in the collection, you'll need to implement INotifyPropertyChanged on those items (the item's class).

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      1 Reply Last reply
      0
      • E Eric Vonjacson

        Hi, I have some problem withe multi binding in wpf: 1) In the widnow cs file, I define a property like this:

        private ObservableCollection<string> colltest = new ObservableCollection<string>();
        public ObservableCollection<string> Coll
        {
          get
          {
            return this.colltest;
          }
        }
        
        1. In the xaml file define a multi binding to the "togglebutton".

          <ToggleButton Tag="dd" Content="TT" Width="50" Height="50">
          <ToggleButton.IsChecked>
          <MultiBinding Mode="OneWay" Converter="{x:Static app:SimpleConverter.Instance}">
          <Binding Mode="OneWay" RelativeSource="{RelativeSource Mode=FindAncestor,AncestorType={x:Type app:Window1}}"
          Path="Coll" />
          <Binding Mode="OneWay" RelativeSource="{RelativeSource Mode=Self}" Path="Tag" />
          </MultiBinding>
          </ToggleButton.IsChecked>
          </ToggleButton>

        2. and the covnert function of the converter is like this:

          public object Convert(object[] value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
          {
          bool bflag = false;

          if (value[0] == DependencyProperty.UnsetValue || value[0] == null||
          value[1] == DependencyProperty.UnsetValue ||
          value[1] == null)
          return bflag;

          ObservableCollection<string> v1 = value[0] as ObservableCollection<string>;
          string v2 = (string)value[1];

          if (v1 != null)
          {
          bflag = v1.Contains(v2);
          }

          return bflag;
          }

        It's working after the window is loadded. But however, after I add some new string to the collection "colltest", the togglebutton's "IsChecked" is not updated automatically. I want it working in this way: If any changes are made to the collection "colltest". The togglebutton's "IsChecked" could update accordingly. So how to resolve this problem? thanks.

        I Offline
        I Offline
        Ian Shlasko
        wrote on last edited by
        #3
        1. If it's a problem setting up the data binding, the error will NOT display like an exception, but will show up in the Output window. Open that up and watch for any messages. That should let you know if it's finding the binding source. 2) If that much is working, drop a breakpoint in your Convert routine, and step through to see if the flag is being updated properly.
        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

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