0
У меня есть XAML, который отлично работает (вместе с классом myRectConverter). Единственная проблема - мне нужно, чтобы это было преобразовано в код VB.NET, чтобы он мог быть создан в приложении динамически.WPF VB.NET RectangleGeometry Rect Structure Multibinding
<Canvas Grid.Column="0" Grid.Row="0" Height="{Binding ElementName=FeatureOverlay1, Path=ActualHeight}" HorizontalAlignment="Stretch" Name="Canvas1" VerticalAlignment="Stretch" Width="{Binding ElementName=FeatureOverlay1, Path=ActualWidth}" Background="Red">
<Canvas.Clip>
<RectangleGeometry x:Name="clipRect" RadiusX="5" RadiusY="5">
<RectangleGeometry.Rect>
<MultiBinding Converter="{StaticResource myRectConverter}">
<Binding ElementName="Canvas1" Path="Width"/>
<Binding ElementName="Canvas1" Path="Height"/>
</MultiBinding>
</RectangleGeometry.Rect>
</RectangleGeometry>
</Canvas.Clip>
<Image Canvas.Left="0" Canvas.Top="0" Name="TestImage" Stretch="Fill" Source="/FluidSize;component/Images/Desert.jpg" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</Canvas>
Вот то, что я до сих пор:
Dim rectGeometry As RectangleGeometry = New RectangleGeometry
rectGeometry.RadiusX = 5
rectGeometry.RadiusY = 5
Dim multiBinding As MultiBinding = New MultiBinding()
multiBinding.Converter = New RectConverter
Dim binding As Binding = New Binding()
binding.ElementName = "Canvas1"
binding.Path = New PropertyPath("Width")
multiBinding.Bindings.Add(binding)
binding = New Binding()
binding.ElementName = "Canvas1"
binding.Path = New PropertyPath("Height")
multiBinding.Bindings.Add(binding)
' Need to somehow add the multibinding object to the rectGeometry as a Rect structure, then assign to Canvas1.Clip
Кто-нибудь знает, как получить эту работу?
Благодаря
Бен
Привет Кент. Спасибо за предложение, однако они, похоже, не достигают ожидаемого результата. rectGeometry не имеет SetBinding, поэтому я использовал опцию BindingOperations. Когда вызывается класс RectConverter, я получаю следующую ошибку: «Преобразование из типа« NamedObject »в тип« Double »недопустимо». Если я просматриваю объекты в отладчике, я вижу, что структура Rect пуста, а свойства Canvas1 Width/Height привязаны к корню объекта RectangularGeometry, а не к структуре Rect. –