c# - 如何将 xaml 转换为代码隐藏?

标签 c# .net xaml code-behind

<TextBlock x:Name="Block" Foreground="White" FontSize="13">
    <SLMultiBinding:BindingUtil.MultiBinding>
        <SLMultiBinding:MultiBinding TargetProperty="Text" Converter="{StaticResource ConverterConcat}">
            <Binding Path="name"/>    
            <Binding Path="name"/>                          
        </SLMultiBinding:MultiBinding>
    </SLMultiBinding:BindingUtil.MultiBinding>
</TextBlock>

我只能翻译

var binding = new MultiBinding()
{
    TargetProperty = "Text",
    Converter = new Restaurant.Helpers.Converter.ConcatConverter(),
    Bindings = new ObservableCollection<Binding>()
    {
        new Binding("name"), 
        new Binding("name")
    }
};

最佳答案

您正在寻找如何设置 Attached Property .

在您的情况下,它将类似于 BindingUtil.SetMultiBinding(Block, binding);

关于c# - 如何将 xaml 转换为代码隐藏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6223652/

相关文章:

c# - Windows 8 CollectionViewSource ObservableCollection 绑定(bind)不更新

c# - 在异常情况下完成 Saga

c# - 我在什么情况下运行 C#?

c# - 为什么我的 StackPanel 不在生成的类中? (空引用异常)

c# - Dotnet 核心中的 AOP : Dynamic Proxy with Real Proxy in Dotnet core

.net - 在 GDI+ 中绘制具有自定义透明度的图像

c# - 如何在窗口中居中弹出窗口(Windows 商店应用程序)

silverlight - 使用 Segoe WP 字体的等宽 TextBlock

c# - HttpClient 和 PushStreamContent

c# - SqlCommand INSERT INTO 从 datagridview 到 SQL DB 表