I'm creating a paint simular program. I Draw System.Windows.Shapes, to a canvas in a UserControl. However I Can name my shapes using the Line l = new Line; l.Name Now I would Like to add more than one name to this Line l, Maybe 10 diffrent names. How can I do this? I Have had some ideas but they are all very complicated.
Maybe I was a bit unclear. Example. l.Name = "name_1"; l.Name2 = "material2"; I need to be able to tie my FrameworkElement with these other names. However I don't need to be able to find an FrameworkElement with these other names.
The ideas that I have came up with is very complicated. One of those is to put the FrameworkElement Name to ID_xxxx, and print this ID to a textfile and then add more information about this ID in this text file. Then to read this I Will read lines between etc ID_1 and ID_2 and then figure out what "material" ID_1 is. This feels very complicated and stupid, so I figured StackOverflow might have some suggestions for me.
Thanks Mikael Törnqvist
Related
I am writing CodedUI tests for a web application. There are three text boxes with the same name and I would like to know how do we call these text boxes ? Please advise ?
Use this:
var control = new HtmlControl(parent)
control.SearchProperties.Add([Control Type], [Control Name]);
var specificControl = control.FindMatchingControls()[index]
In the above code, what it does is find the three controls you mentioned with the same name, and then index them in a collection. By taking a piece of that collection with "[index]", you can isolate a single control.
This is what it looks like in practice in a WPF app:
//Identify the cell and minimize button 2017
WpfCell currentyearCell = new WpfCell(workWindow);
currentyearCell.SearchProperties.Add(WpfCell.PropertyNames.Value, DateTime.Now.AddYears(0).ToString("yyyy"));
currentyearCell = currentyearCell.FindMatchingControls()[0] as WpfCell;
If 3 elements has same property and if you will provide a search properties
Control.searchproperties.add("","")
And you intend to select 2 element.Than by this approach it will automatically identify the first element.
Just go for next sibling search configuration.
So it will go the next element or we can use children element[pass the index]
I use Visual-Studio-2012. Basically I have 5 column DataGridView with product,quantity,price,+,- and I would like to align all text of products I put into my basket as MiddleCentered except actual Product description (it stays MiddleLeft as default).
I can change aligment via RowHeadersDefaultCellStyle, but I can't choose which columns I would like to align and it makes all of them MiddleCentered.
Is there any way to do so? I was trying to search on the NET, but didn't find anything clear. Help would be very appreciated.
As you have not posted your code, here is a way to aligning the text,
dataGridView1.Columns["ColumnName"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
Give a try and if you still not able to align the text, please post your code.
Holly spirit, I found the answer. I can change it via Edit Columns, selecting column and changing aligment. How stupid do I feel now. Damn...Sorry to bother guys.
I want to make a static column header in WPF datagrid, so the user will see the column headers/names, when scrolling down if table is too long.
However, I am really new to this WPF/C# thing, and I am no sure how to do it, and if it will be in cs part, or xaml part. I have searched many possible solutions, but most of them were for asp.net link or I found even nice HTML/CSS solution to this, or even some plugins to do so.
However, my question remains - how to make datagrid column header static, and should I do it in cs part or xaml part?
Thanks
Edit: as I am just fixing larger part of code, it would be too difficult to post it all. However, I read those problems with scrolviewer, and I found there this part of code, which might have caused it:
var scrollViewer = new ScrollViewer()
{
HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
VerticalScrollBarVisibility = ScrollBarVisibility.Auto
};
scrollViewer.AddHandler(UIElement.MouseWheelEvent, new RoutedEventHandler(this.MouseWheelHandler), true);
var stackPanel = new StackPanel();
scrollViewer.Content = stackPanel;
So - could this caused it, and do you have advice how to fix it? Thanks in advance
I am creating a word document(2010) using c#.
It consists of a large table weith cells and within the cells paragraphs.
I Have achieved this with a little with (i hope simple) a little niggly issue. In front of every piece of text there is a block of empty space.
I am attempting to get rid of this space with no luck.
To build the table I have pretty much followed this example.
http://msdn.microsoft.com/en-us/library/office/gg490656.aspx
I have tried fiddling with the sacing of the cells, of the table rows and of the table cells but i'm unsure if i am using the right properties.
I have tried appending new ContextualSpacing() { Val = false } to table row and cells with no luck. I've also tried new Spacing with no luck either!
Any ideas hints tips would be muchly appreciated
I found that setting the style to a style within word resolved the issue. This was a manual process and then i looked in to how to do this programatically.
DocumentFormat.OpenXml.Wordprocessing.TableStyle tableStyle2 = new DocumentFormat.OpenXml.Wordprocessing.TableStyle() { Val = "TableGrid" };
Append this item to the table and it all worked perfectly!
ive got for example 25 panels that are formed like a grid (5 rows, 5 columns),
if i click at one of those i want to get e.g. the panel above too.
at first i named the panels like their positions e.g. PanelX1Y1, PanelX1Y2 ...
then i took the coords out of the name and created the new coords...
and after i got the new name, i used a foreach loop to go through all the items and get that one with the right name.
ive already tried it with the winforms positions so i took the positions of the clicked one addet e.g. 25 pixels and lopped through all the items in form and checked them via their location.
But i dont want to looped through all the items ...
how can i get the item if i know its name whitout to loop through all items and check for their names..
can i use this:
this.Controls["name"];
okay my grid:
p11 p12 p13
p21 p22 p23
p31 p32 p33
if i click on p31 i want to change something at p31 and p21 so i need the object p21
To directly answer you question, you can use the Find() method of the ControlCollection class. e.g.:
myForm.Controls.Find("panelX1Y2")
To suggest a better method, don't use strings for something like this. It is hackish and sloppy.
Instead, initialize your panels in a 2D array and use the array indices to find the right panel.
Could you not use a dictionary? Remember that a dictionary isn't ordered if this is important to you.
Dictionary<string, Panel> dcPanels = new Dictionary<string, Panel>();
dcPanels.Add("GridA", new Panel());
Panel p = dcPanels["GridA"];