首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >来自FrameworkElementFactory类型组合框的Interaction.GetBehaviors

来自FrameworkElementFactory类型组合框的Interaction.GetBehaviors
EN

Stack Overflow用户
提问于 2019-01-29 22:58:24
回答 1查看 124关注 0票数 0

我试图隐藏一个从FrameworkElementFactory设置的动态组合框。如果我尝试组合框作为参数,我会得到错误' Combobox‘是一个类型,这在给定的上下文中是无效的,如果我尝试fElement作为参数,那么它会给出错误“无法从'System.Windows.FrameworkElementFactory’转换为'System.Windows.DependencyObject'”我需要C#而不是xaml或ASP.net中的解决方案。

代码语言:javascript
复制
 FrameworkElementFactory fElement = new FrameworkElementFactory(typeof(ComboBox));

       fElement.SetValue(ComboBox.WidthProperty, 125D);
            fElement.SetValue(ComboBox.ItemsSourceProperty, choices);
            fElement.SetValue(ComboBox.DisplayMemberPathProperty, "Value");
            fElement.SetValue(ComboBox.SelectedValuePathProperty, "Value");
            fElement.SetValue(ComboBox.NameProperty, "CONAAM" + rowOnderdeel.OnderdeelID);
            //fElement.SetValue(ComboBox.NameProperty, Onderdeelnaam);
            fElement.AddHandler(Selector.SelectionChangedEvent, new SelectionChangedEventHandler(cbCursistOnderdeelResultaat));
            fElement.SetBinding(ComboBox.TextProperty, bind);
            Interaction.GetBehaviors(ComboBox).Add(new HideComboxBehavior());
EN

回答 1

Stack Overflow用户

发布于 2019-01-30 23:42:58

解决方案是使用System.Windows.Style和使用setter来触发组合框的可见性。

代码语言:javascript
复制
FrameworkElementFactory fElement = new FrameworkElementFactory(typeof(ComboBox));
                    fElement.SetValue(ComboBox.WidthProperty, 125D);
                    fElement.SetValue(ComboBox.ItemsSourceProperty, Resultaten);
                    fElement.SetValue(ComboBox.DisplayMemberPathProperty, "Value");
                    fElement.SetValue(ComboBox.SelectedValuePathProperty, "Key");
                    fElement.SetValue(ComboBox.SelectedValueProperty, new Binding(column.ColumnName));

                    Style cbStyle = new Style(typeof(ComboBox));
                    Setter cbSetter = new Setter(ComboBox.VisibilityProperty, Visibility.Visible);                  
                    cbStyle.Setters.Add(cbSetter);

                    DataTrigger cbDataTrigger = new DataTrigger();
                    Binding cbBinding = new Binding(column.ColumnName);

                    cbDataTrigger.Value = 0;

                    Setter cbDataSetter = new Setter(ComboBox.VisibilityProperty, Visibility.Hidden);

                    cbDataTrigger.Setters.Add(cbDataSetter);
                    cbDataTrigger.Binding = cbBinding;
                    cbStyle.Triggers.Add(cbDataTrigger);               

                    fElement.SetValue(ComboBox.StyleProperty, cbStyle);

                    DataTemplate dataTemplate = new DataTemplate();
                    dataTemplate.VisualTree = fElement;
                    gvc.CellTemplate = dataTemplate;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54423819

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档