【问题标题】:How Can I Convert Xaml Code To C# (Setter Property in WPF)如何将 Xaml 代码转换为 C#(WPF 中的 Setter 属性)
【发布时间】:2011-11-01 02:00:43
【问题描述】:

我有一个关于将 Xaml 转换为 C# 的问题,我正在使用自动完成框选项卡顺序无法正常工作这意味着首先我们移动所有控件,最后我继续自动完成框我通过 xaml 代码解决了这个问题

<ToolKit:AutoCompleteBox.TextBoxStyle>
    <Style TargetType="TextBox">
        <Setter Property="TabIndex"
                Value="{Binding ElementName=txtFirstName, Path=TabIndex}"/>
    </Style>
</ToolKit:AutoCompleteBox.TextBoxStyle>

现在在另一个我使用 All Control Dynamic 所以没有 Xaml 用于自动完成我的所有工作都将完成但我面临相同的选项卡顺序问题如何从 C# 转换上述 Xaml 代码

ctrl = new AutoCompleteBox { FontSize = 14, MaxDropDownHeight = 90 };
//Here We need to Implement That Style
ctrl.TabIndex = c.TabOrder;
ctrl.MaxWidth = 200;
if (c.SpName != null && c.DisplayMember != null)
{
    DataTable dt = sqlHelper.ExecuteSelectProcedure(c.SpName);
    var cmb = ctrl as AutoCompleteBox;
    cmb.ItemsSource = dt.AsEnumerable().Select(r => r.Field<string>(c.DisplayMember)).ToList();
}

请帮帮我谢谢和问候

沙申克·蒂亚吉

【问题讨论】:

    标签: c# wpf xaml autocomplete styles


    【解决方案1】:

    有一个应用程序可以做到这一点,即 XamlT。 在 WPF/SL 应用程序上,您可以在某些方面使用 XAML 或 C#/VB.NET 代码(例如,创建故事板或设置图像源)。

    最好的问候

    【讨论】:

      【解决方案2】:
      var style = new Style(typeof(TextBox));
      var binding = new Binding("TabIndex") { ElementName = "txtFirstName" };
      var setter = new Setter(TextBox.TabIndexProperty, binding);
      style.Setters.Add(setter);
      ctrl.TextBoxStyle = style;
      

      【讨论】:

      • 我在上面的 Xaml 中还有一个查询...自动完成框的 ISTABSTOP 属性默认为 True ....如果我将其设置为 false 并删除样式,那么它可以工作,然后我可以移动完美的制表符,但在自动完成框中,光标没有出现
      【解决方案3】:
      else if (c.Type == typeof(AutoCompleteBox))
      {
          //var style = new Style(typeof(TextBox));
          ctrl = new AutoCompleteBox { FontSize = 14, MaxDropDownHeight = 90, Name = c.ControlID };
          ctrl.TabIndex = c.TabOrder;
          ctrl.MaxWidth = 200;
      
          var style = new Style(typeof(TextBox));
          var binding = new Binding("TabIndex") { ElementName = c.ControlID };
          var setter = new Setter(TextBox.TabIndexProperty, binding);
          style.Setters.Add(setter);
          (ctrl as AutoCompleteBox).TextBoxStyle = style;
      
          if (c.SpName != null && c.DisplayMember != null)
          {
              DataTable dt = sqlHelper.ExecuteSelectProcedure(c.SpName);
              var cmb = ctrl as AutoCompleteBox;
              cmb.ItemsSource = dt.AsEnumerable().Select(r => r.Field<string>(c.DisplayMember)).ToList();
          }
      }
      

      此代码完美运行

      【讨论】:

        猜你喜欢
        • 2019-05-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-07
        相关资源
        最近更新 更多