I am creating a custom wpf user control in VB.Net 2015. The control will be used to display a card, in this example a 3 of spades. In top of the card, I will sometimes display a graphic. In this example, it will be a small check mark. Both card and check mark are xaml code which will be pulled from resource dictionary.
My problem is in loading the card and check graphic dynamically through VB.net code behind. I can display either the card or the check mark, but can not get both to display at the same time.
This is my user control definition.
<UserControl x:Class="CardControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:TestingNested"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Viewbox Name="CardBox">
<Canvas Width="128" Height="182" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!-- card graphic to be pulled in here when needed -->
<Viewbox Name="CheckBox">
<!-- check mark graphic to be pulled in here when needed -->
</Viewbox>
</Canvas>
</Viewbox>
</UserControl>
This is the code I am using to attempt to display card with check mark on it.
Private Sub button_Deal_Click(sender As Object, e As RoutedEventArgs)
Dim x As New CardControl
canvas_1.Children.Add(x)
x.Height = 182
x.Width = 128
Canvas.SetLeft(x, 100)
Canvas.SetTop(x, 50)
'comment out this line below to verify that check mark will display
x.Content = FindResource("3S")
With x.CheckBox
Canvas.SetLeft(x.CheckBox, 35)
Canvas.SetTop(x.CheckBox, 1)
.Child = FindResource("CHECK")
End With
End Sub
With the code written this way, the control will display the card 3 of spades. If I comment out the line x.Content = FindResource("3S"), then the program will display the check mark. But I can not display both at same time.
I have tried to research this and believe I need some sort of binding, but have been unable to make it work. Any help would be greatly appreciated.
What I have tried:
I have tried putting some binding statements in, but as of yet have not found a way which will work. I don't quite have a good understanding of the binding yet, and as such, not even sure that is the problem.
I have read many posts on binding, but most are in C and a bit hard for me to follow.