UWP Use Shy Header for ListView - c#

I basically copied code from here and then changed variables to mine. I have also copied the files under the folder ExpressionBuilder.
And inside the ShyHeader.cs, there is such line of code:
var scrollViewer = gridView.GetFirstDescendantOfType<ScrollViewer>();
So I tried same thing for my ListView but it says undefined:
SongsListView.GetFirstDescendantOfType<ScrollViewer>()
So I put a ScrollViewer around the SongsListView and use that. But I fail to get it working for my project. The header is neither sticky above nor shy. It just gets scrolled normally. Can anyone help me debug it?
SongsListView is here.
SongsListView is used here in HeaderedPlaylistControl.
ShyHeader is implement here at the bottom.
HeaderPlaylistControl is used in AlbumPage, MyFavoritesPage and PlaylistsPage.

So I tried same thing for my ListView but it says undefined
This is extension method for DependencyObject. You could find it here and copy it to you project.
So I put a ScrollViewer around the SongsListView and use that. But I fail to get it working for my project.
I checked your code, you need call SetShyHeadermet method when
PlaylistInfoGrid loaded.
private void PlaylistInfoGrid_Loaded(object sender, RoutedEventArgs e)
{
SetShyHeader();
}

Related

uwp c# 2019: How to refer to RootGrid

Sorry. I think I've found it.
I thought the suggestion reference to "RootGrid" was to a VS Named Space, like System.Windows.RootGrid I'm relatively sure they intended me to refer to a Grid in my XAML.
Realizing this probability was a "DUH" moment. So, just replacing RootGrid with my XAML name "GridBoard" will probably solve the issue. I haven't got the close of the Control to work yet, but he naming issue is at least being found.
To answer the question. Help, is a User control file in ScqWander Program. localUCHelp was the name used to create an instance on the Page.
Quick overview: How do I refer to RootGrid?
I get RootGrid "Does not exist in current context"
I am using VS 2019 and have a C# project, using XAML. I wrote a UserControl and am trying code a Button to Close the control (when clicked work from within the control). I got a suggestion which included the sample below. Google has turned up nothing.
The code is within the namespace
public sealed partial class MainPage : Page
void Page_Loaded(object sender, RoutedEventArgs e)
{
ScqWander.Help localUCHelp = new ScqWander.Help();
localUCHelp.HelpUserControlCloseEvent += new EventHandler(BtnPXClose);
RootGrid.Chilren.Add(localUCHelp);
}
I was simply thinking that "RootGrid" reference to which I could refer (as in Using System.Whateverxxxx) when I should have been referring to the Grid I defined in my XAML. I just did not recognize what was being said in the example.

wpf window throws exception when trying to show

I created a WPF application and it runs perfectly on several computers.
There is one computer that keeps throwing an "Object reference not set to an instance of an object." exception.
I can't install Visual Studio on that computer, but i found the line that causes the problem:
var m_GCSWindow = new GCSWindow();
m_GCSWindow.Show();
everything runs perfectly until the Show().
i can't figure this one out because:
it works on all the other computers.
it's MVVM, no code behind.
what could be the problem?
Edit:
I was finally able to install visual studio on the problematic computer, and found that if i remove a single line from the XAML everything loads ok.
<Image Source="{Binding MapView.MapImage,Converter={StaticResource ImageConverter}}"
Stretch="None" MouseLeftButtonDown="Image_MouseLeftButtonDown"
ContextMenu="{StaticResource MapRightClick}" />
so i thought the problem might be in the converter, and put a break point in it, but the exception occurs before.
Edit 2:
After a little more investigation i found that MouseLeftButtonDown="Image_MouseLeftButtonDown" is what causes the problem.
when i remove that line everything works.
private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (ImageClickCommand != null) ImageClickCommand.Execute(e.GetPosition(sender as IInputElement));
}
that's the code, and i put a break point in it but still i never get there.
I even tried moving the event to another control, but i still have the same issue.
Maybe m_GCSWindow is null perhaps you could put in a null check .
Does GCSWindow reside in a DLL? Maybe the DLL is missing? Maybe one of its depdencies is missing.
You could also put a try catch around that call
I've had this issue before. The bug can probably be found in the converter
Try debugging the converter
Make sure it gets called
Make sure it gets the value that you want it to convert
Make sure it doesn't crash when converting
Make sure you get the value you want
Etc etc etc
Also - Can you post the code for ImageConverter?

Functions like Focus() and properties like Focusable not available for silverlight, only .NET?

Short version: Solutions like the following: How Do I Give a Textbox Focus in Silverlight?
Don't seem to work because functions like Focus and properties like Focusable DON'T EXIST for silverlight and only exist for .net apparently.
Background/Long Version: So I've been trying to get my XNA game to work on silverlight. Porting it was a nightmare but I managed to do it somehow. Currently I want to use ViewBox's so my game is as big as a players browser instead of a set size. When I tried to do it, it VISUALLY worked, but it was impossible to send any keyboard commands to the game. I'm pretty sure its preventing me from focusing it. When I google how to give focus, it gives me links like these where people are saying to use functions like .focus() which DON'T EXIST on silverlight 5 only .NET apparently. For example go here: http://msdn.microsoft.com/en-us/library/system.windows.controls.control(v=vs.110).aspx
It shows the .NET 4.5 version. If you change it to silverlight at the top, all the nice functions and settings disappear. Am I missing something here? How do I access the .Net versions of these classes in silverlight? If its not possible why are all those answers mentioned above use Focus() etc?
Assuming C#...
On your silverlight page, select yourPage_Created from write code menu
Add the following:
partial void YourPage_Created() // this line should be autogenerated
{
this.FindControl("YourControl").ControlAvailable += YourFieldAvailable;
}
private void YourFieldAvailable(object sender, ControlAvailableArguments e)
{
((System.Windows.Controls.Control)e.Control).GotFocus += YourRoutine;
}
private void YourRoutine(object sender, System.Windows.RoutedEventArgs e)
{
// do your focus specific code in here
}
You will now have a custom focus event for the specified control.
Hope this helps :)

Visual Studio Package: Settings the visibility of a custom Solution Explorer context menu item

I am creating a Visual Studio Package (this is my first time) and my end goal is to create a context-menu item for the solution explorer that only works on certain file types. (I thought this would be a common thing, but didn't find any decent tutorials on it, so if you know any please let me know)
I followed a simple MSDN guide to create an item in the toolbar first (I forget where is was to link it) and this worked fine.
Then I found a way to move it to the Solution Explorer context menu. This was achieved by manipulating the .vsct file and having an element like this:
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_ITEMNODE"/>
That probably doesn't matter, but I am trying to set the scene.
Now, because I want to only show the item for certain file types, I need to find a way to check the file when the right-click button is pressed. Cutting a long search short, I found this and ended up with the following code:
protected override void Initialize()
{
//stuff
OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
menuItem.BeforeQueryStatus += menuItem_BeforeQueryStatus;
//more stuff
}
void menuItem_BeforeQueryStatus(object sender, EventArgs e)
{
var myCommand = sender as OleMenuCommand;
myCommand.Text = "NEW NAME";
}
In the above example I am just trying to set the text to try and prove it works, I know there is a Visible property but I want this step to work first. The BeforeQueryStatus event is fired, and debugging shows the code executing as expected. However, there is no change in the context menu item, it stays with the original text.
What am I missing here? Why is it not updating?
OK, so I have finally found a solution to this problem, there are a couple of things that you need to do...
STEP 1:
We need to specify that the VSPackage should "auto-load", we do this so that the code will execute when the ContextMenu is shown, because normally the VSPackage would not initialise before the UI has been shown (i.e. the menu item has been clicked). To do this we add an attribute to the Package class, like so:
[ProvideAutoLoad("{f1536ef8-92ec-443c-9ed7-fdadf150da82}")]
public sealed class MyFirstPackage : Package
You may wonder what that GUID value is, well in this case it represents the UICONTEXT_SolutionExists constant, which means the the package will auto-load when a solution exists (so when we create a new one or load one). I got this information from here, as you might be able to tell there are a number of different VSConstants that could be used.
Here are a couple more resources that list other GUID values that can be used:
GUID List 1
GUID List 2
STEP 2:
Now that the BeforeQueryStatus code is executing at the correct place, it is still confusing as to why the code doesn't actually change anything (in my question I try to change the Text). Well, the answer is, because we need to give the package permission to do so (at least that's the way I see it as being).
To do this we must edit the .vsct file. Inside there we can find a Buttons element, inside which should be our ContextMenu Button. By default there are some comments which mention the use of the CommandFlag node - this is what we want.
In order to give permission for our package to change the Text we must add the following node:
<CommandFlag>TextChanges</CommandFlag>
Now, if we run the VSPackage it should all work as expected!
If you are looking to allow permission to change the Visibility of the menu item (which was my original aim) then you can use the following CommandFlag:
<CommandFlag>DynamicVisibility</CommandFlag>
There is a full list of command flags here, with descriptions on what they do.
Instead of directly using the guid mentioned in musefan's answer, you can use:
[ProvideAutoLoad(Microsoft.VisualStudio.Shell.Interop.UIContextGuids.SolutionExists)]
Refer to: UIContextGuids Class for all guid constants.

How to hide textboxes, labels and buttons C# WPF

I would like to hide several textboxes, a label and a button as soon as a button is clicked... however, for some reason, my code doesn't seem to cause this effect. Nothing appears to happen. I'm using WPF.
Here is my code:
private void doSomething_Click(object sender, RoutedEventArgs e)
{
Name.Visibility = Visibility.Hidden;
}
This code doesn't seem to work.. any ideas?
I believe Visibility.Collapsed is what you need and not Visibility.Hidden.
EDIT: Did you try follow up this code with UpdateLayout() method of parent element/component?
Your code seems to work fine, the "Signing in..." label appears after everything else disappear. I suggest you to just copy all your code from the .xaml.cs file and the .xaml file into a new project, but make sure you don't copy the first line"<Window x:Class="..." because it could generate an error if the class name isn't the same in the new project.
For the xaml code I suggest you not think the same as you design windows forms applications. WPF has the layout system, which re-orientates or re-sizes its elements when re-sizing the window. So you should not specify exact numbers in the margin property as if they where coordinates. Create a grid, create rows or columns for each element and then just set the horizontal or vertical alignment or margins. Think different than the old windows forms way.
I've run your code... and it's working great for me. I've not changed anything (except the variable names) so I guess it's a bug from VS.
As said nikolamm94 try to add this.UpdateLayout(); at the end of connect_Click it might help. I tried and it is still working fine. Or maybe create a new VS projet, it already worked for me a few times.
Sorry my answer is not the most helpful, I wanted to put a comment instead but I don't have enough reputation :/
Please refer: https://msdn.microsoft.com/en-us/library/ms748821(v=vs.85).aspx
Set to Visible: tb1.Visibility = System.Windows.Visibility.Visible;
Set to Hide: tb1.Visibility = System.Windows.Visibility.Hidden;
You can hide a textbox by going to properties->appearance->visibility, then setting it to "hidden"

Categories