-
Notifications
You must be signed in to change notification settings - Fork 225
Open
Labels
VB -> C#Specific to VB -> C# conversionSpecific to VB -> C# conversion
Description
When I begin with the following in VB:
<Window x:Class="MainWindow" x:Name="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp3"
mc:Ignorable="d"
Title="MainWindow" Height="200" Width="200">
<Grid>
<TextBlock Height="100" Background="{Binding ElementName=MainWindow, Path=AwesomeColor}"/>
</Grid>
</Window>
Class MainWindow
Public Property AwesomeColor As Brush
Get
Return GetValue(AwesomeColorProperty)
End Get
Set(value As Brush)
SetValue(AwesomeColorProperty, value)
End Set
End Property
Public Shared AwesomeColorProperty As DependencyProperty = DependencyProperty.Register(
"AwesomeColor", GetType(Brush), GetType(MainWindow), New PropertyMetadata(Brushes.Yellow))
End Class
It is converted to the following in XAML:
<Window x:Class="MainWindow" x:Name="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp3"
mc:Ignorable="d"
Title="MainWindow" Height="200" Width="200">
<Grid>
<TextBlock Height="100" Background="{Binding ElementName=MainWindow, Path=AwesomeColor}"/>
</Grid>
</Window>
However, the code will not compile; instead, it should be as follows:
<Window x:Class="WpfApp3.MainWindow" x:Name="MainWindowRoot"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp3"
mc:Ignorable="d"
Title="MainWindow" Height="200" Width="200">
<Grid>
<TextBlock Height="100" Background="{Binding ElementName=MainWindowRoot, Path=AwesomeColor}"/>
</Grid>
</Window>
I had to add the namespace WpfApp3. to x:Class, and I had to change x:Name not to be the same as x:Class. This also means I have to change all of the binding element names.
GrahamTheCoder
Metadata
Metadata
Assignees
Labels
VB -> C#Specific to VB -> C# conversionSpecific to VB -> C# conversion