WPF Project has wrong version of OpenGL - wpf

I have two separate WPF projects.
My goal: Alter project B to have the same OpenGL object instance version as project A.
Both instantiate a variable 'gl' at some point with the following line:
OpenGL gl = args.OpenGL;
After setting a breakpoint and check 'gl' for its object properties, I see the following in project A:
Version = "4.4.13084 Compatibility Profile Context 14.301.1001.0"
Yet in project B, I see the following:
Version = "1.1.0"
Concerning 'args' both projects instantiate gl in the following method:
private void OpenGLControl_OpenGLInitialized(object sender, OpenGLEventArgs args)
Both projects call that method with:
((SharpGL.WPF.OpenGLControl)(target)).OpenGLInitialized += new SharpGL.SceneGraph.OpenGLEventHandler(this.OpenGLControl_OpenGLInitialized);
Notice that 'args' is not being passed in from here explicitly. I figured function must be called in a deeper context like OpenGLEventHandler. However, I noticed that args is a parameter to that function as well.
public delegate void OpenGLEventHandler(object sender, OpenGLEventArgs args);
I don't have access to source code for OpenGLEventHandler since it is in SceneGraph.dll
I am wondering if the args variable is determined by a .config or .xaml file since my project is a WPF being run from Visual Studio. However, there isn't much differences in the files concerning OpenGL.
Project A's MainWindow.xaml:
<Window x:Class="ObjectLoadingSample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Object LoadingSample" Height="600" Width="800"
xmlns:sharpGL="clr-namespace:SharpGL.WPF;assembly=SharpGL.WPF">
<Grid>
<DockPanel>
<ToolBarPanel DockPanel.Dock="Top">
<Menu>
<MenuItem Header="_File">
<MenuItem x:Name="fileOpenItem" Header="_Open..." Click="fileOpenItem_Click" />
</MenuItem>
</Menu>
</ToolBarPanel>
<ToolBarTray DockPanel.Dock="Top">
<ToolBar>
<Label Target="{Binding ElementName=textBoxScale}">Scale: </Label>
<TextBox x:Name="textBoxScale" Width="60" IsEnabled="False">1</TextBox>
<CheckBox x:Name="checkBoxAutoScale" IsChecked="True" IsEnabled="False">Auto</CheckBox>
<Separator />
<Label Target="{Binding ElementName=comboBoxRenderMode}">Render Mode: </Label>
<ComboBox x:Name="comboBoxRenderMode" Width="100" SelectedIndex="1">
<ComboBoxItem>Immediate</ComboBoxItem>
<ComboBoxItem>Retained</ComboBoxItem>
</ComboBox>
<Label Target="{Binding ElementName=comboBoxPolygonMode}">Polygon Mode:</Label>
<ComboBox x:Name="comboBoxPolygonMode" Width="100" SelectedIndex="2" SelectionChanged="comboBoxPolygonMode_SelectionChanged">
<ComboBoxItem>Points</ComboBoxItem>
<ComboBoxItem>Lines</ComboBoxItem>
<ComboBoxItem>Polygons</ComboBoxItem>
</ComboBox>
</ToolBar>
</ToolBarTray>
<sharpGL:OpenGLControl x:Name="openGlCtrl"
OpenGLDraw="OpenGLControl_OpenGLDraw" OpenGLInitialized="OpenGLControl_OpenGLInitialized"
RenderContextType="FBO" Resized="OpenGLControl_Resized" />
</DockPanel>
</Grid>
</Window>
Project B's MainWindow.xaml
<Window x:Class="ProjectBeta.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sharpGL="clr-namespace:SharpGL.WPF;assembly=SharpGL.WPF"
Title="MainWindow" Height="800" Width="800">
<Grid>
<sharpGL:OpenGLControl OpenGLDraw="OpenGLControl_OpenGLDraw" OpenGLVersion="OpenGL4_3" OpenGLInitialized="OpenGLControl_OpenGLInitialized" DrawFPS="True" Margin="-3,0,3,0" />
</Grid>
</Window>
There are other files like App.config, App.xaml, and Settings.settings, however, I don't know which ones would be most useful to share.

Related

WPF - DataBinding (Command is not being executed)

I am writing a WPF application where I wish to implement the MVM pattern.
My code is currently set up like this:
This is my view model class where I am exposing the command I wish to be executed as a property
```
public HomeScreenViewModel(NavigationService mw)
{
this.mw = mw;
}
private RelayCommand _addStudent;
public ICommand AddStudent
{
get
{
if (_addStudent == null)
{
_addStudent = new RelayCommand(param => this.OpenNewStudents(), param => true);
}
return _addStudent;
}
}
This is my xaml containing the layout of the corresponding view
<Page x:Class="test.HomeScreen"
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:test"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="1300"
Title="HomeScreen">
<WrapPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<WrapPanel HorizontalAlignment="Center" Height="300" Margin="0,0,0,0" VerticalAlignment="Center" Width="1300">
<Button Content="AddStudent" Command="{Binding AddCommand}" Style="{StaticResource ButtonStyle}" />
<Button Content="AddStudent" Style="{StaticResource ButtonStyle}" />
<Button Content="AddStudent" Style="{StaticResource ButtonStyle}" />
<Button Content="AddStudent" Style="{StaticResource ButtonStyle}" />
<Button Content="AddStudent" Style="{StaticResource ButtonStyle}" />
<Button Content="AddStudent" Style="{StaticResource ButtonStyle}" />
<Button Content="AddStudent" Style="{StaticResource ButtonStyle}" />
<Button Content="AddStudent" Style="{StaticResource ButtonStyle}" />
<TextBox Text="{Binding Path=HI}" Width="200" Height="200"/>
</WrapPanel>
<Canvas Margin="350, 100,0, 0" Height="300" Width="1350" VerticalAlignment="Center" HorizontalAlignment="Center">
<Image Source="Logo.PNG"/>
</Canvas>
</WrapPanel>
I have set the command of the top button using the binding syntax in the WrapPanel.
This HomeScreen page is linked from a naviagation window and is the source of the navigation window (xaml file):
<NavigationWindow x:Class="test.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:test"
mc:Ignorable="d"
Title="School Management App" Height="350" Width="1250"
Source="HomeScreen.xaml">
</NavigationWindow>
I have my HomeScreen view constructor set like this:
public partial class HomeScreen : Page
{
public HomeScreen()
{
InitializeComponent();
this.DataContext = new HomeScreenViewModel(this.NavigationService);
}
}
My infrastructure is set up as I have described above and my implementation of relay command is taken from this site https://msdn.microsoft.com/en-us/magazine/dd419663.aspx.
When I run my application and I press the corresponding button, nothing happens. I was wondering if someone could help me figure out what is wrong and why the command binding isn't working. It would be much appreciated, thanks :)
as a side note, could someone give me some tips on what the best way to debug wpf applications and figure out what bindings exist at run time.
Thanks :)
your command name is AddStudent, but you use AddCommand in xaml. Just correct the name:
Command="{Binding AddStudent}"

Binding example

I have been trying for weeks to find a decent article that explains WPF Binding simply and with a working example that actually explains what is happening. Yes there are lots of examples out there but lots of those refer to older versions of everything involved.
I am trying to write an application, that is not web based, uses WPF and VB on VS2012.
In this bit of code i am updating a screen field directly, but i want to learn how to update a variable in memory and it update on the screen automatically, how do i get from here to there - In stages with explanations
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Test Bind"
Height="299" Width="500" WindowStartupLocation="CenterScreen">
<DockPanel HorizontalAlignment="Stretch" LastChildFill="False" VerticalAlignment="Stretch">
<DockPanel DockPanel.Dock="Top" Height="64">
<Button Content="Button" Height="64" VerticalAlignment="Top" Width="75" Click="Button_Click" />
<TextBox Height="64" Width="120" Text="TextBox1" x:Name="clickcount" />
<TextBox Height="64" Width="120" x:Name="textBox2" Text="{Binding Test, Mode=Default}" />
</DockPanel>
</DockPanel>
</Window>
Class MainWindow
Public Shared clcount As Integer = 0
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
clcount = clcount + 1
Me.clickcount.Text = clcount.ToString
End Sub
End Class

Unable to reference/bind to view template in user control

I have a view template in a user control as below
<UserControl
x:Class="Configuration.Views.viewProfileTemplate"
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"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid Background="Azure" Width="233">
<StackPanel Height="300" HorizontalAlignment="Left" Name="stackPanel1" VerticalAlignment="Top" Width="230">
<TextBox Text="{Binding Path=SomeProfileText}" Margin="10" />
<ListBox ItemsSource="{Binding Path=Profiles}" Height="70" Margin="10"/>
<CheckBox Content="CheckBox" Height="16" Name="checkBox1" Width="175" />
</StackPanel>
</Grid>
</UserControl>
The user control is defined as below in the main.xaml window
<Window x:Class="Configuration.TreeUI"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:views="clr-namespace:Configuration.Views"
xmlns:local="clr-namespace:Configuration"
Title="TreeUI" Height="300" Width="450" WindowStyle="ToolWindow">
I atempt to use the template with
<DataTemplate DataType="{x:Type local:ProfileViewModel}">
<Views:viewProfileTemplate/>
</DataTemplate>
But the compiler reports :
Error 1 The type 'Views:viewProfileTemplate' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
I again am missing som important point, but what ?
Going to owe someone a big drink .....
There are two potential causes for this:
1) If the data template is in a different assembly than viewProfileTemplate, you need to make the xaml reflect this:
xmlns:views="clr-namespace:Configuration.Views;assembly=ViewAssembly"
Note that this will also require a reference to be added to the project properly to function.
2) If this is a design time error, make sure to build the solution first. The WPF designer in VS often will report errors about missing types until you've built once, then it "works" properly.

WPF command pattern

I have an application wide flag that is an app setting.
MyApp.Properties.Settings.Default.SoundMuted
The flag is if my apps sound is muted. I have a number of windows where sounds are being played through .Net’s sound player. I was thinking the flag would be wired up to a toolbar button with a command. I was thinking for muting notification to have my classes that play sound wire up to a class (e.g. SoundManager) hanging off the app that implements NotifyPropertyChange. Then if the user clicks the toolbar button, I would set the Muted property in my SoundManager and have all the soundplayer classes get the PropertyChange and mute.
Is there a better pattern for this? Say I could wire all the soundplayers up to the command and that command would fire.
Also is there some slick way to just wire that app setting as a bindable property in xaml?
Although I've always done the same approach as in my other answer in knocking up that example I have realized that it is unnesssasary. You can bind to the Settings object directly, like this:
<Window x:Class="Test_WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyApp"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<local:Settings x:Key="SettingsRes"/>
</Window.Resources>
<Grid>
<Menu>
<MenuItem Header="Audio">
<MenuItem Header="Mute" IsCheckable="True"
IsChecked="{Binding Path=Default.SoundMuted, Source={StaticResource ResourceKey=SettingsRes}}"/>
</MenuItem>
</Menu>
<TextBlock Text="{Binding Path=Default.SoundMuted, Source={StaticResource ResourceKey=SettingsRes}}" Height="23" HorizontalAlignment="Left" Margin="18,156,0,0" VerticalAlignment="Top" Width="75" />
</Grid>
</Window>
Again, multiple instances of that resource still work well together, e.g. bind the TextBlock to a second resource:
<Window x:Class="Test_WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyApp"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<local:Settings x:Key="SettingsRes"/>
<local:Settings x:Key="SettingsRes2"/>
</Window.Resources>
<Grid>
<Menu>
<MenuItem Header="Audio">
<MenuItem Header="Mute" IsCheckable="True" IsChecked="{Binding Path=Default.SoundMuted, Source={StaticResource ResourceKey=SettingsRes}}"/>
</MenuItem>
</Menu>
<TextBlock Text="{Binding Path=Default.SoundMuted, Source={StaticResource ResourceKey=SettingsRes2}}" Height="23" HorizontalAlignment="Left" Margin="18,156,0,0" VerticalAlignment="Top" Width="75" />
</Grid>
</Window>
One way is to make a wrapper class to provide bindable access to the static Settings.Default.
I have since realized this is more work than is needed, please see my other answer
namespace MyApp
{
internal sealed class ResourceWrapper
{
public Settings Default
{
get
{
return Settings.Default;
}
}
}
}
Now, we need to add that as a resource somewhere, could be done in App.xaml, here I've done local to the window that is using it, don't forget the namespace:
xmlns:local="clr-namespace:MyApp"
<Window.Resources>
<local:ResourceWrapper x:Key="SettingsWrapper"/>
</Window.Resources>
Now we need to bind to that, this shows it's use in a MenuItem on that same window:
<Menu>
<MenuItem Header="Audio">
<MenuItem Header="Mute" IsCheckable="True"
IsChecked="{Binding Path=Default.SoundMuted, Source={StaticResource ResourceKey=SettingsWrapper}}"/>
</MenuItem>
</Menu>
Like I said, you can add the resource at the app level or you can create multiple of these ResourceWrappers in different windows/controls, they will all point to the same static underneith.
That full xaml for window with a test TextBlock:
<Window x:Class="Test_WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyApp"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<local:ResourceWrapper x:Key="SettingsWrapper"/>
</Window.Resources>
<Grid>
<Menu>
<MenuItem Header="Audio">
<MenuItem Header="Mute" IsCheckable="True" IsChecked="{Binding Path=Default.SoundMuted, Source={StaticResource ResourceKey=SettingsWrapper}}"/>
</MenuItem>
</Menu>
<TextBlock Text="{Binding Path=Default.SoundMuted, Source={StaticResource ResourceKey=SettingsWrapper}}" Height="23" HorizontalAlignment="Left" Margin="18,156,0,0" VerticalAlignment="Top" Width="75" />
</Grid>
</Window>

Error about UserControl not supported in WPF in Expression Blend 2

I've created a test Silverlight 2 app in Visual Studio, just copying the Tim Heuer video, but when I go to open it in Blend I get this error
UserControl is not supported in a Windows Presentation Foundation (WPF) project
This is the XAML code
<UserControl x:Class="MyFirstApp.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel Orientation="Vertical">
<TextBox x:Name="myTextBox" FontSize="60" />
<Button Content="Click Me" FontSize="60" Click="Button_Click" />
</StackPanel>
</Grid>
</UserControl>
Am I missing a reference or something?
You need to install Expression Blend 2.0 SP1.
Please take a look at this thread:
http://social.expression.microsoft.com/Forums/en-US/blend/thread/33030347-c99a-4f41-8be7-089c92e4ab2d

Resources