This is absolutely ridiculous! I'm trying to change the color of inkCanvas through code but it doesn't work. I saw a lot of tutorials about that and they don't work for me. Even though they're straightforward. I'm new to WPF but still - this should be a no-brainer.
*Note: I can set the color through XAML but that's a one-time operation and not what I want.
My code:
using System.Windows;
using System.Windows.Controls;
using System.Windows.Ink;
using System.Windows.Media;
namespace WpfApplication1
{
public partial class MainWindow : Window
{
InkCanvas inkCanvas = new InkCanvas();
public MainWindow()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(SetColor);
}
// doesn't work
private void SetColor(object sender, RoutedEventArgs e)
{
inkCanvas.DefaultDrawingAttributes.Color = Colors.Red;
}
// doesn't work either
private void Button_Click(object sender, RoutedEventArgs e)
{
inkAttributes.Color = Colors.Blue;
}
}
}
Edit: My XAML was:
<Window...
< InkCanvas Name="inkCanvas" /> ....