Building Out-Of-The-Box Tutorial Examples

lmstearn

Member
Joined
Dec 1, 2017
Messages
6
Location
Australia
Programming Experience
3-5
Hi there,
With VS2017 15.5.2, building Resources from Code-behind, the final topic on this tutorial page:
Get:


Error The name "UserControl1" does not exist in the namespace "clr-namespace:WpfApplication3".
Error CS0103 The name 'InitializeComponent' does not exist in the current context
Error CS0103 The name 'tbTest' does not exist in the current context
Having tried most of the suggested workarounds from SO, not a clue as to where to go from here- is it something to do with views at all?



Also compiling Custom Dependency Properties from the final topic on this tutorial page:
Get:

Step into: Stepping over non-user code 'WpfTutorialSamples.App.InitializeComponent'
An unhandled exception of type 'System.IO.IOException' occurred in PresentationFramework.dll
Cannot locate resource 'wpf%20application/resourcesfromcodebehindsample.xaml'.


resourcesfromcodebehindsample.xaml
was never created- does it want to be?

WpfTutorialSamples.jpg
Thanks for reading!
 
Last edited:

lmstearn

Member
Joined
Dec 1, 2017
Messages
6
Location
Australia
Programming Experience
3-5
For the first one, all that had to be done was to replace
C#:
StartupUri="WPF application/ResourcesFromCodeBehindSample.xaml">
with
C#:
StartupUri="MainWindow.xaml"
...
Golly gosh, the wrong errors were posted for the CustomDependencies:

Let's repost them:
C#:
Error        The name "UserControl1" does not exist in the namespace "clr-namespace:WpfApplication3".    CustomDependencies
Error    CS0103    The name 'InitializeComponent' does not exist in the current context    CustomDependencies
Error    CS0103    The name 'tbTest' does not exist in the current context    CustomDependencies
 
Last edited:

lmstearn

Member
Joined
Dec 1, 2017
Messages
6
Location
Australia
Programming Experience
3-5
Code Added to Illustrate Issue

Here's the code-behind:
C#:
[COLOR=#000088]using[/COLOR] [COLOR=#7F0055]System[/COLOR][COLOR=#666600];[/COLOR] 
[COLOR=#000088]using[/COLOR] [COLOR=#7F0055]System[/COLOR][COLOR=#666600].[/COLOR][COLOR=#7F0055]Collections[/COLOR][COLOR=#666600].[/COLOR][COLOR=#7F0055]Generic[/COLOR][COLOR=#666600];[/COLOR] 
[COLOR=#000088]using[/COLOR] [COLOR=#7F0055]System[/COLOR][COLOR=#666600].[/COLOR][COLOR=#7F0055]Linq[/COLOR][COLOR=#666600];[/COLOR] 
[COLOR=#000088]using[/COLOR] [COLOR=#7F0055]System[/COLOR][COLOR=#666600].[/COLOR][COLOR=#7F0055]Text[/COLOR][COLOR=#666600];[/COLOR] 
[COLOR=#000088]using[/COLOR] [COLOR=#7F0055]System[/COLOR][COLOR=#666600].[/COLOR][COLOR=#7F0055]Threading[/COLOR][COLOR=#666600].[/COLOR][COLOR=#7F0055]Tasks[/COLOR][COLOR=#666600];[/COLOR] 

[COLOR=#000088]using[/COLOR] [COLOR=#7F0055]System[/COLOR][COLOR=#666600].[/COLOR][COLOR=#7F0055]Windows[/COLOR][COLOR=#666600];[/COLOR] 
[COLOR=#000088]using[/COLOR] [COLOR=#7F0055]System[/COLOR][COLOR=#666600].[/COLOR][COLOR=#7F0055]Windows[/COLOR][COLOR=#666600].[/COLOR][COLOR=#7F0055]Controls[/COLOR][COLOR=#666600];[/COLOR] 
[COLOR=#000088]using[/COLOR] [COLOR=#7F0055]System[/COLOR][COLOR=#666600].[/COLOR][COLOR=#7F0055]Windows[/COLOR][COLOR=#666600].[/COLOR][COLOR=#7F0055]Data[/COLOR][COLOR=#666600];[/COLOR] 
[COLOR=#000088]using[/COLOR] [COLOR=#7F0055]System[/COLOR][COLOR=#666600].[/COLOR][COLOR=#7F0055]Windows[/COLOR][COLOR=#666600].[/COLOR][COLOR=#7F0055]Documents[/COLOR][COLOR=#666600];[/COLOR] 
[COLOR=#000088]using[/COLOR] [COLOR=#7F0055]System[/COLOR][COLOR=#666600].[/COLOR][COLOR=#7F0055]Windows[/COLOR][COLOR=#666600].[/COLOR][COLOR=#7F0055]Input[/COLOR][COLOR=#666600];[/COLOR] 
[COLOR=#000088]using[/COLOR] [COLOR=#7F0055]System[/COLOR][COLOR=#666600].[/COLOR][COLOR=#7F0055]Windows[/COLOR][COLOR=#666600].[/COLOR][COLOR=#7F0055]Media[/COLOR][COLOR=#666600];[/COLOR] 
[COLOR=#000088]using[/COLOR] [COLOR=#7F0055]System[/COLOR][COLOR=#666600].[/COLOR][COLOR=#7F0055]Windows[/COLOR][COLOR=#666600].[/COLOR][COLOR=#7F0055]Media[/COLOR][COLOR=#666600].[/COLOR][COLOR=#7F0055]Imaging[/COLOR][COLOR=#666600];[/COLOR] 
[COLOR=#000088]using[/COLOR] [COLOR=#7F0055]System[/COLOR][COLOR=#666600].[/COLOR][COLOR=#7F0055]Windows[/COLOR][COLOR=#666600].[/COLOR][COLOR=#7F0055]Navigation[/COLOR][COLOR=#666600];[/COLOR] 
[COLOR=#000088]using[/COLOR] [COLOR=#7F0055]System[/COLOR][COLOR=#666600].[/COLOR][COLOR=#7F0055]Windows[/COLOR][COLOR=#666600].[/COLOR][COLOR=#7F0055]Shapes[/COLOR][COLOR=#666600];[/COLOR]  

[COLOR=#000088]namespace[/COLOR] [COLOR=#7F0055]WpfApplication3[/COLOR] [COLOR=#666600]{[/COLOR] 
   [COLOR=#880000]/// <summary> [/COLOR]
      [COLOR=#880000]/// Interaction logic for UserControl1.xaml [/COLOR]
   [COLOR=#880000]/// </summary> [/COLOR]
    
   [COLOR=#000088]public[/COLOR] [COLOR=#000088]partial[/COLOR] [COLOR=#000088]class[/COLOR] [COLOR=#7F0055]UserControl1[/COLOR] [COLOR=#666600]:[/COLOR] [COLOR=#7F0055]UserControl[/COLOR] [COLOR=#666600]{[/COLOR] 
    
      [COLOR=#000088]public[/COLOR] [COLOR=#7F0055]UserControl1[/COLOR][COLOR=#666600]()[/COLOR] [COLOR=#666600]{[/COLOR] 
         [COLOR=#7F0055]InitializeComponent[/COLOR][COLOR=#666600]();[/COLOR] 
      [COLOR=#666600]}[/COLOR]
        
      [COLOR=#000088]public[/COLOR] [COLOR=#000088]static[/COLOR] [COLOR=#000088]readonly[/COLOR] [COLOR=#7F0055]DependencyProperty[/COLOR] [COLOR=#7F0055]SetTextProperty[/COLOR] [COLOR=#666600]=[/COLOR] 
         [COLOR=#7F0055]DependencyProperty[/COLOR][COLOR=#666600].[/COLOR][COLOR=#7F0055]Register[/COLOR][COLOR=#666600]([/COLOR][COLOR=#008800]"SetText"[/COLOR][COLOR=#666600],[/COLOR] [COLOR=#000088]typeof[/COLOR][COLOR=#666600]([/COLOR][COLOR=#000088]string[/COLOR][COLOR=#666600]),[/COLOR] [COLOR=#000088]typeof[/COLOR][COLOR=#666600]([/COLOR][COLOR=#7F0055]UserControl1[/COLOR][COLOR=#666600]),[/COLOR] [COLOR=#000088]new[/COLOR] 
            [COLOR=#7F0055]PropertyMetadata[/COLOR][COLOR=#666600]([/COLOR][COLOR=#008800]""[/COLOR][COLOR=#666600],[/COLOR] [COLOR=#000088]new[/COLOR] [COLOR=#7F0055]PropertyChangedCallback[/COLOR][COLOR=#666600]([/COLOR][COLOR=#7F0055]OnSetTextChanged[/COLOR][COLOR=#666600])));[/COLOR] 
                
      [COLOR=#000088]public[/COLOR] [COLOR=#000088]string[/COLOR] [COLOR=#7F0055]SetText[/COLOR] [COLOR=#666600]{[/COLOR] 
         [COLOR=#000088]get[/COLOR] [COLOR=#666600]{[/COLOR] [COLOR=#000088]return[/COLOR] [COLOR=#666600]([/COLOR][COLOR=#000088]string[/COLOR][COLOR=#666600])[/COLOR][COLOR=#7F0055]GetValue[/COLOR][COLOR=#666600]([/COLOR][COLOR=#7F0055]SetTextProperty[/COLOR][COLOR=#666600]);[/COLOR] [COLOR=#666600]}[/COLOR] 
         [COLOR=#000088]set[/COLOR] [COLOR=#666600]{[/COLOR] [COLOR=#7F0055]SetValue[/COLOR][COLOR=#666600]([/COLOR][COLOR=#7F0055]SetTextProperty[/COLOR][COLOR=#666600],[/COLOR] value[COLOR=#666600]);[/COLOR] [COLOR=#666600]}[/COLOR] 
      [COLOR=#666600]}[/COLOR] 
        
      [COLOR=#000088]private[/COLOR] [COLOR=#000088]static[/COLOR] [COLOR=#000088]void[/COLOR] [COLOR=#7F0055]OnSetTextChanged[/COLOR][COLOR=#666600]([/COLOR][COLOR=#7F0055]DependencyObject[/COLOR] d[COLOR=#666600],[/COLOR]
         [COLOR=#7F0055]DependencyPropertyChangedEventArgs[/COLOR] e[COLOR=#666600])[/COLOR] [COLOR=#666600]{[/COLOR] 
         [COLOR=#7F0055]UserControl1[/COLOR] [COLOR=#7F0055]UserControl1Control[/COLOR] [COLOR=#666600]=[/COLOR] d [COLOR=#000088]as[/COLOR] [COLOR=#7F0055]UserControl1[/COLOR][COLOR=#666600];[/COLOR] 
         [COLOR=#7F0055]UserControl1Control[/COLOR][COLOR=#666600].[/COLOR][COLOR=#7F0055]OnSetTextChanged[/COLOR][COLOR=#666600]([/COLOR]e[COLOR=#666600]);[/COLOR] 
      [COLOR=#666600]}[/COLOR] 
        
      [COLOR=#000088]private[/COLOR] [COLOR=#000088]void[/COLOR] [COLOR=#7F0055]OnSetTextChanged[/COLOR][COLOR=#666600]([/COLOR][COLOR=#7F0055]DependencyPropertyChangedEventArgs[/COLOR] e[COLOR=#666600])[/COLOR] [COLOR=#666600]{[/COLOR] 
         tbTest[COLOR=#666600].[/COLOR][COLOR=#7F0055]Text[/COLOR] [COLOR=#666600]=[/COLOR] e[COLOR=#666600].[/COLOR][COLOR=#7F0055]NewValue[/COLOR][COLOR=#666600].[/COLOR][COLOR=#7F0055]ToString[/COLOR][COLOR=#666600]();[/COLOR] 
      [COLOR=#666600]}[/COLOR]  
   [COLOR=#666600]}
[/COLOR]}
And here's the XAML:
C#:
[COLOR=#000088][FONT=Menlo]<Window[/FONT][/COLOR][COLOR=#7F0055][FONT=Menlo]x:Class[/FONT][/COLOR][COLOR=#666600][FONT=Menlo]=[/FONT][/COLOR][COLOR=#008800][FONT=Menlo]"WpfApplication3.MainWindow"[/FONT][/COLOR]   [COLOR=#7F0055]xmlns[/COLOR] [COLOR=#666600]=[/COLOR] [COLOR=#008800]"http://schemas.microsoft.com/winfx/2006/xaml/presentation"[/COLOR] 
   [COLOR=#7F0055]xmlns:x[/COLOR] [COLOR=#666600]=[/COLOR] [COLOR=#008800]"http://schemas.microsoft.com/winfx/2006/xaml"[/COLOR] 
   [COLOR=#7F0055]xmlns:views[/COLOR] [COLOR=#666600]=[/COLOR] [COLOR=#008800]"clr-namespace:WpfApplication3"[/COLOR]
   [COLOR=#7F0055]Title[/COLOR] [COLOR=#666600]=[/COLOR] [COLOR=#008800]"MainWindow"[/COLOR] [COLOR=#7F0055]Height[/COLOR] [COLOR=#666600]=[/COLOR] [COLOR=#008800]"350"[/COLOR] [COLOR=#7F0055]Width[/COLOR] [COLOR=#666600]=[/COLOR] [COLOR=#008800]"604"[/COLOR][COLOR=#000088]>[/COLOR] 
    
   [COLOR=#000088]<Grid>[/COLOR] 
      [COLOR=#000088]<views:UserControl1[/COLOR] [COLOR=#7F0055]SetText[/COLOR] [COLOR=#666600]=[/COLOR] [COLOR=#008800]"Hellow World"[/COLOR][COLOR=#000088]/>[/COLOR] 
   [COLOR=#000088]</Grid>[/COLOR] 
[COLOR=#000088][FONT=Menlo]</Window>[/FONT][/COLOR]
There's an issue with views:UserControl1 from the reposted errors in the previous post.
The code references the Grid class, but there is no explicit reference to "Views" on that MSDN page.
Neither can the compiler find UserControl1 or tbTest in the namespace.
We can make the InitializeComponent error go away with:
C#:
public partial class UserControl1 : MainWindow
But that leaves UserControl1 not being a UserControl.
Any suggestions as how MainWindow is to be referenced in MainWindow.xaml.cs for the controls to appear on the form?
Thanks for reading!
 
Last edited:
Top Bottom