Windows form code pass to WPF - c#

i am trying to make a Column header in WPF by using code like this
listview.Columns.Add("Name",100);
listview.View = View.Details;
listview.FullrowSelect = true;
listview.GridLines = True;
and the error is always saying that i need System.windows.Controls.Listview but when i added the class using System.Windows.Controls.Listview; it's the same error

Please have a look here, I think this is something that you are trying to achieve.
Adding Columns programatically to listview in WPF?

Please notice that WPF use Presentation DLL to construct UI while normal windows from use System.Windows.Forms. As a result, you can't use the Win Form' s control in WPF, you can use gridview instead, please refer to Moeen' s link

Related

How to make an accordion style content holder UWP

So i am trying to make an accordion content holder for an uwp application. I can't find anything resembling what i want to achive in the documentation. Is this someting i need to build from scratch using stackpanels and codebehiend ect ect, or are there tools I can use within the libary which I havent found yet ?
Here Is an example of what i want. When the users clicks on a vaccine name, a content box containg information about that vaccine will dropdown. And if it is click while expanded, it will slide back up and only display the name again. An accordion.
Any suggestions, tutorials, articles on the subject will be much appreciated. Thanks in advance.
There is UWP Community Toolkit available that has an expander control that you may be able to utilize. You can get the code sample from the Windows Store and the source code is on github.
https://blogs.windows.com/buildingapps/2016/08/17/introducing-the-uwp-community-toolkit/#v6cSIzET7QwQOb8O.97
I believe from the answer that you know how to make a ListView using DataTemplate. If not search the documentation for this.
So I believe that the most important piece of the question is about the expanding.
First in your DataTemplate bind Height to your DataModel for example like this:
<Grid Height="{x:Bind Item.Height, Mode = OneWay}">...</Grid>
Then place Clicked (or Tapped if its control doesn't support Clicked) event on that arrow, and handle it in the code like this (Tapped may require different arguments but they'll appear automatically anyway):
Arrow_Clicked(object sender, RoutedEventArgs e)
{
var item = (sender as Button).DataSource as Item;
if (item.Height == 80)
item.Height = 200;
else
item.Height = 80;
}

Setting ContextMenu Style to 2013

I'm trying to change the default style of the contextmenu to 2013/2015 in my rehosted vs13 application.
The problem occurs in only one designer, everywhere else its the correct one. I've tried to override both the XAML code and the code behind, checked if something else was changing the style, but without anykind of result.
Is there even a way to change the default style? Am I overseeing something?
Okay, after some heavy research/try and error if finally found out what was wrong: I couldnt access the control I wanted to change the ordinary way, so I had to think outside of the box (and ask a collegue for help).
This is the code that works for me, its not pretty, but it deletes the 'standard'-style set by WPF.
var dv = wd.Context.Services.GetService<DesignerView>();
dv.MenuItemStyle = null;
dv.MenuSeparatorStyle = null;
dv.Resources[typeof(ContextMenu)] = new Style(typeof(ContextMenu));
Quick thanks to Glen Thomas for trying to help.

What WP 8.1 XAML control could look and behave like the system Task switcher?

I'm writing a Windows Phone 8.1 Store app and I need to create a control so that it looks and behaves similar to WP 8.1 system task switcher (that appears when holding back hardware button).
It should show some images and support sliding left or right when swiping. Does anyone know what control should I use or do I need to create a completely new control from scratch?
So, the sollution was easy. The control I was looking for was... a ScrollViewer. It has 2 properties in WinRT XAML that make the ScrollViewer scrolling behave like I wanted: HorizontalSnapPointsAlignment and HorizontalSnapPointsType.
If you want to try this behavior, this MSDN code sample will expose it for you.
One point to mention. If you wish to set such behavior to, for example, a ListView you should firstly get its internal ScrollViewer in code and then set its HorizontalSnapPointsAlignment and HorizontalSnapPointsType properties. You can use GetFirstDescendantOfType<T>() extension method from WinRT XAML toolkit.
var sv = myListView.GetFirstDescendantOfType<ScrollViewer>();
sv.HorizontalSnapPointsAlignment = SnapPointsAlignment.Center;
sv.HorizontalSnapPointsType = SnapPointsType.Mandatory;

How to add link Labels at run time in Windows form

I have been making a Windows Form Application in C# using the Visual C# 2008 IDE.
There are basically two forms in my application. One is created at Runtime and it's layout is undefined and the second one's predefined.
Now, I have been adding form elements using the toolbox provided and don't have any idea how to add them using written code(not using toolbox). I want to add n number of Labels to the second form which is undefined. n can be anything(decided at runtime, depending on the user's input). Can anybody tell me what is the efficient way to do this?
Just a quick example of a "dynamic control" being created at run-time and added to the form:
Label lbl = new Label();
lbl.Text = "Hello World!";
lbl.Location = new Point(100, 25);
this.Controls.Add(lbl);
You can replace "this" with the container to add it to, like "panel1" for instance. For containers that have their own layout engine, like a FlowLayoutPanel, then you wouldn't need to specify a Location().
Create a new LinkLabel(), set its properties (in particular, text and position), then add it to the Controls collection of your form or any panel.
You may also want to add event handlers, and store them somewhere (probably in a List<T>) so you can change or remove them later.
Create one in the designer, configure it's properties as you wish. Then go to the designer file, which name is like Form1.Desiner.cs, copy the code related to your LinkLabel (find everything with text search) and paste it where you wish :)

C# -- C++ Intellisense textbox

Is there a way to make a textbox control display C++ intelisense just like it would in Visual Studios?
See This Question and this 'DIY Intellisense' Code Project from the top answer. That's in C#, but the same set of controls is accessable through C++.
I assume you are talking about embedding a control in your own app. You could look at Actipro SyntaxEditor. It will color the C++ right out of the box. If you want intelliprompt/sense you will have supply a parser. They have stuff to help you get started.
I gather you are talking about an AutoComplete popup, not actual intellisense.
To do this, set the AutoCompleteMode of the textbox to Suggest (or SuggestAppend) and choose the appropriate AutoCompleteSource
combDogBreeds.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
combDogBreeds.AutoCompleteSource = AutoCompleteSource.ListItems;
string[] validDogBreeds = new[] {"Bull Mastiff", "Bulldog", "Golden Retriever"};
combDogBreeds.Items.AddRange(validDogBreeds);
Or, in the designer:

Categories

Resources