I cannot set the Button.Visibility = Visibility.Collapsed on any of my buttons.
Below is the xaml
<Button x:Name="createPageButton" Content="Create Page" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="740,75,0,0" Height="61" Width="175" FontSize="24" FontWeight="Bold" Click="CreatePageButton_Click" />
<Button x:Name="TestButton" Content="Button" HorizontalAlignment="Left" Margin="1699,705,0,0" VerticalAlignment="Top" Visibility="Collapsed"/>
In my code behind I try to set the Visibility property.
TestButton.Visibility = Visibility.Visible;
I get the following error msg.
Error CS0176 Member 'Visibility.Visible' cannot be accessed with an instance reference; qualify it with a type name instead
I cannot reproduce your issue with your code above. It worked well on my side with invoking it for example, inside the click event handle.
private void CreatePageButton_Click(object sender, RoutedEventArgs e)
{
TestButton.Visibility = Visibility.Visible;
}
My UWP app version is target build 15063.
Error CS0176 Member 'Visibility.Visible' cannot be accessed with an instance reference; qualify it with a type name instead
But for this error, it seems like you are trying to access static members with instance syntax which is not allowed. Details please reference this similar thread. If you still have issues please upload a minimal reproduced project.
Updated:
If you are using the WindowsTemplateStudio, by default in the template studio blank app, the page doesn't reference the Windows.UI.Xaml namespace (which Visibility class is belong to), so that thrown this error. Just add this reference it will work well.
using Windows.UI.Xaml;
In my case, the cause was due to a conflict in the imports / using namespaces. It seems that I had two namespaces which have the same naming.
To fix this issue, I had to specify the exact class reference: System.Windows.Visibility
Related
I'm trying to make an interface with multiple language options on a WPF screen. I'm writing the name of the text block I want to add to my Resources file and my code, but on the xaml screen "The member "Manuals" is not recognized or is not accessible." I get an error. I am getting this error in all the buttons and texts I try to add. Can you help me understand why? There is my xaml code line and resources designer cs project code line. Thanks in advance.
public static string _Manual
{
get
{
return ResourceManager.GetString("Manuals", resourceCulture);
}
}
<TextBlock Name="ttbManuals" Grid.Row="8" Text="{x:Static resx:Resources._Manual}" HorizontalAlignment="Left" Margin="0,0,0,-20" VerticalAlignment="Top" Height="39" Width="580" Style="{DynamicResource CncTextBlock}" Background="{DynamicResource BackgroundBrush1}" Padding="10,5,0,0"/>
The Resources class is by default created as internal. For use in XAML it needs however to be public.
To fix it, select the resx file in solution explorer and in the properties, change ResXFileCodeGenerator to PublicResXFileCodeGenerator.
See also here: Visual Studio - Resx File default 'internal' to 'public'
Well, I'd like to use a class of a namespace in my Mainwindow.xaml
Image
As you see the namespace called WPF.Tools
Now I create a local at the top to the XAML
xmlns:webutil="WPF.Tools"
And in the Grid I have a WebBrowser where I'd like to use a a method of the class of the namespace:
<WebBrowser webutil:WebBrowserBehaviors.BindableSource="{Binding SelectedRSSFeed.Link}" Grid.Column="1" Margin="10,10,10,10" Grid.RowSpan="3" Grid.Row="0"/>
If I hover over it it says: The name "WebBrowserBehaviors" does not exist in the namespace "WPF.Tools".
I also added a Project Reference so I don't think this is the Problem
Your reference seems wrong.
It should be:
xmlns:webutil="clr-namespace:WPF.Tools;assembly=WPF.Tools
So I have a project where I am setting up a resource variable named TEST (Right clicking on the project in the Solution Explorer, choosing Properties, then choosing Resources) and I want to pass those into a textbox on a WPF XAML form. It seems to be different than if I try to use a normal variable but alas, I am befuddled.
Can anyone guide me please on how to pass the variable thru please?
Thank you.
I know this is not the correct method
======================================
<TextBlock Text="{Binding Bottle_1_Title}" FontWeight="Bold" FontSize="32" HorizontalAlignment="Center" TextAlignment="Center"></TextBlock>
This is also not valid and I am not seeing the intellisense to help me
<TextBlock Text="{resource.test}"
In my wpf application i am trying to use windows form control.... but i am getting an error i.e
Error The type 'WindowsFormsHost' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
can any one help me to get it done... the following is my code
c#:code
public Window2()
{
InitializeComponent();
System.Windows.Forms.PictureBox PictureBox1 = new System.Windows.Forms.PictureBox();
windowsFormsHost1.Child = PictureBox1;
PictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(PictureBox1_Paint);
}
xaml:code
<WindowsFormsHost Height="175" HorizontalAlignment="Left" Margin="10,10,0,0" Name="windowsFormsHost1" VerticalAlignment="Top" Width="255" />
Normally when we see an error that says:
The type SomeClass was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built
There could be a few problems. Either that means that we didn't add a reference of the relevant dll to our project, or we didn't import the namespace properly.
To find which dll we need to add a reference to, we normally go to MSDN, searching with the search terms 'SomeClass class'... in your case 'WindowsFormsHost class'. Doing this for the WindowsFormsHost class, we see this:
Note the line that says:
Assembly: WindowsFormsIntegration (in WindowsFormsIntegration.dll)
Looking in the Add Reference dialog in Visual Studio, we can see a dll entry for WindowsFormsIntegration:
So that's how we find out which dll to import. Now, we just need to make sure that we import the namespace properly, either in C#:
using System.Windows.Forms.Integration;
In XAML, you do not need to add an XML Namespace for the WindowsFormsIntegration dll before using the WindowsFormsHost control.
<WindowsFormsHost>
<!-- Some WinForms Control -->
</WindowsFormsHost>
See the WindowsFormsHost Class page on MSDN for more information.
I have two files in my VS project: Custom.xaml and Custom.cs
In my XAML file, I have the following text boxes:
<TextBox x:Name="TextBox1" Text="{Binding Value, Mode=TwoWay}" Foreground="Black" Background="Green" SelectionChanged="TextBox1_SelectionChanged" />
<TextBox x:Name="TextBox2" Text="{Binding Value, Mode=TwoWay}" Foreground="Black" Background="Green" SelectionChanged="TextBox2_SelectionChanged" />
In my .cs, I have the following method:
void TextBox1_SelectionChanged(object sender, RoutedEventArgs e)
{
TextBox t = e.Source as TextBox
}
I can successfully hit the event handler above. Then, I can grab TextBox1 and it's properties by using e.Source, but I would like to access TextBox2 and it's properties.
As a sidenote, the .cs file is just a C# class that I am referencing, not a xaml.cs. Additionally, I understand that I could implement this via a UserControl, but cannot do that in this scenario for reasons that are outside the scope of this post.
Please advise on how I can get/set properties of TextBox2.
Thanks.
EDIT: Any other input on this? As a workaround, I've added an event handler called TextBox2_Loaded, and then set e.Source to an instance variable. Then, in TextBox1_SelectionChanged, I can access the instance variable. Would really like to just target the control directly (ex. TextBox2.IsEnabled). I must be missing a declaration or inheritance somewhere. Can't even find the control using FindName.
Alright, so I apparently had left out a critical component in this post... My TextBox controls are inside of DataTemplate controls. From my research, the TextBox controls cannot be accessed when inside of DataTemplate controls. I really didn't think that would matter, but I guess the instance variables are not created when this scenario exists.
If I've interpreted this incorrectly, please provide input. For now, I've gone ahead and added a Loaded event and defined my TextBox controls as instance variables so that I can access them and change properties when other activities occur.
Thanks for everyone's input.
As long as you have set a namein the XAML, you can access it directly by name (The XAML compiler will create an instance variable for you.)
void TextBox1_SelectionChanged(object sender, RoutedEventArgs e)
{
TextBox t = e.Source as TextBox
TextBox2.Text = "Whatever";
}
This just happened to me. I had to close my solution and reopen it.