Strings.resx cannot be accessed? - c#

<Window x:Class="AFICController.View.WizardDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:view="clr-namespace AFICController.View"
xmlns:res="clr-namespace AFICController.Resources"
Title="{x:Static res:Strings.WizardWelcomeWindow_Title}"
ShowInTaskbar="True"
Width="800"
Height="600"
WindowStartupLocation="CenterScreen"
WindowStyle="SingleBorderWindow"
BorderBrush="#003B7B"
BorderThickness="0"
ResizeMode="CanResize"
Icon="/AFICController;component/Resources/Images/att_icon.ico"
>
<view:WizardView Loaded="WizardView_Loaded_1"/>
</Window>
I want to access my Strings.resx file from my WPF window but it give me following error :
"Strings" does not exist in the namespace "clr-namespace AFICController.Resources".
C:\Users\systellex\Dropbox\Projects\AFICController\AFICController\View\WizardDialog.xaml
\AFICController
I know the problem is at "Title="{x:Static res:Strings.WizardWelcomeWindow_Title}" but I dont know how to sort out the actual error? Can anyone explain where the exact problem exists? Any help would be highly appreciable?

This will also works for..
Also change the Access modifier of your Resource file to Public
Title="{Binding Source={x:Static res:Strings.WizardWelcomeWindow_Title}}"

That depends a bit on your project setup. Very common is
Title="{x:Static Properties.Resources.WizardWelcomeWindow_Title}"

Check you resx-file you have to set the access modificator to public.
Otherwise, no static access methods are created

Related

Control Does Not Exist in Namespace

I'm attempting to use the MediaUriElement in the custom (WPFMediaKit).
I've added it into the namespace like so;
xmlns:controls="clr-namespace:WPFMediaKit.DirectShow.Controls;assembly=WPFMediaKit"
and then I have tried to access it;
<Grid>
<controls:MediaUriElement x:Name="mediaUriElement" />
</Grid>
however I just get an error: The name MediaUriElement does not exist in this namespace. VS does give me a suggestion to use it when I am typing though;
How can I correctly add this into my project?
I've tried and it is worked. What I've done:
Switched project from Framework 4.5 to Framework 4.0
Added references such as DirectShowLib-2005.dll and WPFMediaKit.dll to the project
Declared xaml namespace xmlns:controls="clr-namespace:WPFMediaKit.DirectShow.Controls;assembly=WPFMediaKit" like that:
<Window x:Class="ExcelExportWpfApplication.MainWindow"
... The code omitted for the brevity...
xmlns:controls="clr-namespace:WPFMediaKit.DirectShow.Controls;assembly=WPFMediaKit"
xmlns:vm="clr-namespace:ExcelExportWpfApplication.ViewModel"
mc:Ignorable="d"
Title="MainWindow" Height="550" Width="525"
WindowStartupLocation="CenterScreen">
And just written in xaml:
<controls:MediaUriElement Grid.Row="2"/>
No errors

UserControl content can't be set more than once

having some troubles with UserControl. I cannot get rid of "Content is set more than once error"
From what I've read, the common cause is that .. well, content is set more than once. For example having more than one child or setting content via Content=".." and then specifying another content between the tags.
However, this is UserControl generated by VisualStudio and I made no changes to the xaml.
<UserControl x:Class="TMEGadget.View.Toolbox"
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>
</Grid>
</UserControl>
Got any tips?
P.S: Can anyone tell me why, when I try to type "Hey,\n\nSome text...", the "Hey,\n\n" is deleted?
Edit: Restarting VS fixed the problem , thanks #Bolu

Can't access Windows 8 Store user control from code

I'm writing a Windows 8 Store application and within that I've designed my own user control.
Here is the code for my usercontrol (This is a dummy control but the problem exists with this):
<UserControl
x:Class="Windows8StoreTest.TestUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows8StoreTest"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Width="70"
Height="40">
<StackPanel>
<Button Content="Hello" Foreground="Pink" BorderBrush="Pink"/>
</StackPanel>
</UserControl>
I've dropped the user control onto my page and give it a name:
<Page
x:Class="Windows8StoreTest.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows8StoreTest"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<local:TestUserControl Name="testControl"/>
</Grid>
</Page>
However, when I go to the code behind I can't access the control by that name. It doesn't seem to exist! What is weird is that the control doesn't exists within InitializeComponent() method for the MainPage class which will be why it does exist.
What am I missing from my user control?
I'm using Windows 8 Store, XAML, c#.
Thanks in advance
Try to use this:
<local:TestUserControl x:Name="testControl"/>
Should work...
hello i don't know what is wrong but it should work.i have just made a sample example of it..i am putting it here hope you have done the same way.
<Page
x:Class="App12.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App12"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<local:MyUserControl1 x:Name="hellousercontrol" />
</Grid>
in my mainpage.cs.. i have just use it like this..
public MainPage()
{
this.InitializeComponent();
hellousercontrol.Height = 100;
}
one more this..have build your solution ?
I had the same issue in c++ environment. I observed, I didn't had default constructor in my class, as soon as I added the default constructor, I could use the defined UserControl in my project through XAML file. However without default constructor I was able to use it from within c++ code.

Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception

I am developing wpf C#, and I got this error while I run my application:
This is my Code
<Window x:Class="Hello.Testing"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:r="clr-namespace:Wpf.Controls;assembly=Wpf.TabControl"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="Testing" Height="780" Width="1024" WindowStartupLocation="CenterScreen"
MinWidth="1024" MinHeight="780"
WindowStyle="None" AllowsTransparency="False"
ResizeMode="CanResizeWithGrip" Icon="Resources/Images/Icons/small_icon.ico" Loaded="Window_Loaded">
this is an error that I got:
"Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception".
You sometimes get this error when you use some image (icon in your case) in xaml but have forgotten to include in your project. You must have copied the image in that directory externally but have not yet included it in your project.
Seems you're using kinda markup extension.
Does that markup extension is implemented by yourself?
I remember that the custom MarkupExtension requires you to implement a member method ProvideValue, and seems the exception is on that stack.

Adding x:Name to a user control gives error in generated code of page its used in

I am basically using a user control for the first time, so hopefully it's just a dumb mistake.
I have a simple user control
<UserControl x:Class="TestProject.WebApp.myUserControl"
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"
mc:Ignorable="d"
xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">
<Grid>
<sdk:AutoCompleteBox Name="myACB" ItemsSource="{Binding Data}" FilterMode="StartsWith" MinimumPrefixLength="2" >
</sdk:AutoCompleteBox>
</Grid>
</UserControl>
I am using the control in another page (in a stack panel):
<navigation:Page x:Class="TestProject.WebApp.myPageView"
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"
mc:Ignorable="d"
xmlns:local="clr-namespace:TestProject.WebApp"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation">
<Grid>
<StackPanel Orientation="Horizontal">
<local:myUserControl x:Name="myUC" />
</StackPanel>
</Grid>
</navigation:Page>
The control is in the same namespace as page. Removing the x:Name allows the project to compile and the control functionally works. When x:Name is specified I get an error in the generated code of the page:
Type 'TestProject.WebApp.myUserControl' is not defined.
It happens on these lines of code:
internal TestProject.WebApp.myUserControl myUC;
this.myUC == (TestProject.WebApp.myUserControl)this.FindName("myUC")
I tried with two different controls. Same thing. The generated code has "using TestProject.WebApp;" so I don't know why there is an error only when I have a named instance of the control.
I also cannot seem to use just the Name property. I even tried overloading the NameProperty in the control.
I was able to find a post about this here:
.g.vb file claims that Type X is not defined, even though it is!
Apparently, there is an issue when a project has a service reference (in my case I am using RIA services) and the user control resides in an assembly with the same root namespace as the one you are trying to use it in.
So for me it was,
TestProject.WebApp
Then I tried creating a new project for just the control
TestProject.Controls
Same problem.
Then, when I renamed the project and changed the namespace to
CustomControls
it worked.
Hopefully this saves someone else from some frustration and I really hope this problem can be fixed by MS soon.
What you are showing here should work. What is the default namespace in your project property's? Also did you rename your user control after you created it. Both of those issues could be causing you problems.

Categories

Resources