创建它们之后编程我在C#中创建一个边框和标签的代码WPF
我想创建一个数据与
边境的Background
和BorderBrush
结合标签如何绑定与标签背景边框的背景和BorderBrush通过代码
这里的Background
是代码
void creatlbl()
{
Border b = new Border();
b.Name = "b11";
b.Margin = new Thickness(300,17,0,419);
b.Height = 32;
b.CornerRadius = new CornerRadius(5);
b.Width = 181;
b.BorderThickness = new Thickness(2);
b.HorizontalAlignment = HorizontalAlignment.Left;
lgingrd.Children.Add(b); //
Label l = new Label();
l.Name = "l111";
l.Content = "l111";
l.Height = 28;
l.Width = 177;
l.Foreground = (Brush)bc.ConvertFrom("#FF346D80");
l.FontSize = 20;
l.Background = (Brush)bc.ConvertFrom("#FF9AB426");
l.HorizontalContentAlignment = HorizontalAlignment.Center;
l.Padding = new Thickness(0,0,0,0);
l.Visibility = Visibility.Visible;
b.Child = l;
// here i want to set binding for border
// the background and borderbrush of border equal to the background of label
}
我在XAML做一个按钮一样,
同样的事情<Border x:Name="brdbt" Margin="120,58,0,378"
BorderBrush="{Binding Background, ElementName=bt}" <!--this is the binding which i want-->
Height="32"
CornerRadius="5"
Width="181"
BorderThickness="2"
HorizontalAlignment="Left" Background="{Binding Background, ElementName=bt}">
<Button x:Name="bt" Content="btntxt" HorizontalAlignment="Left" VerticalAlignment="Top" Height="28" Width="177" Click="bt_click" BorderBrush="{x:Null}" Foreground="#FFE8EEF0" FontSize="20" Padding="1,-1,1,1" MouseEnter="bt_mcentr" MouseLeave="bt_mclv" Background="#FFE62828"/>
</Border>
有没有办法做到上面的xaml类型绑定在c#代码边框和标签我在上面提到的c#代码?