I am animating two RenderTransforms of elements in a programmatic way in C# by doing the following:
Storyboard.SetTargetProperty(shiftAnimation, new PropertyPath("RenderTransform.X"));
The problem is, now where I use two transforms, I needed to add a TransformGroup. But I cannot figure out how the path is accessed with it.
TransformGroup.RenderTransform.X or anything similar does not work.
One way would be:
new PropertyPath("RenderTransform.Children[0].X");
and
new PropertyPath("RenderTransform.Children[1].ScaleX");
Though this is kinda static with the hard coded index
Related
I'm working with reorderable lists in Unity right now and I can't seem to figure out how to update the 'max items' field that is visible in the inspector from a script. I'm a little new to Unity so I might be missing something easy but I didn't see any way from the listed methods or properties to update this field. Just looking to set the max items in a reorderable list to the size of a Dictionary that I have populated.
Any help would be appreciated. Thanks.
Edit: Just to be clear, the value I'm trying to change is the bottom one in the screenshot below:
I've tried things along the lines of listName.maxValue = X, listName.maxSize = X, but (at least out of what Visual Studio Code is showing me) there is no method available to change this value. I even tried opening the Reorderable List script (which is from an imported package) and adding my own method for it but it is still throwing an error after trying to use it.
Note that such a class name already exists namely UnityEditorInternal.ReorderableList.
Make sure on top of your file you have
using UnityEngine.UI.Extensions;
instead of
using UnityEditorInternal;
given 2 applications:
1 WPF application, where not all controls have a AutomationId, and which I cannot change. In addition the application adds controls at runtime without setting the AutomationId.
1 console application which automates the above WPF application
I need that, because I want to access all elements within nearly the same amount of time. (searching for an automationelement right before using seems to differ a lot (from ms to s) in the time - depending on the amount of elements / and tree-tiers)
I would like to set AutomationIds of WPFs controls within the console application during WPFs runtime. Would be great to know, if you can think of any solution for this problem!
What I have tried until now:
1.)Reflections
Type type = element.GetType();
FieldInfo fi = type.GetField("AutomationIdProperty");
fi.SetValue(element, "x"); //Error
Error message: "Object of type 'System.String' cannot be converted to type 'System.Windows.Automation.AutomationProperty'" But I would like to hand over a value, not a property type...
if I use the following instead, it throws no error, but changes nothing in the XAML
fi.SetValue(element, AutomationElement.AutomationIdProperty);
2.)directly
AutomationElement element; // = my AutomationElement
element.Current.AutomationId = "x"; //since AutomationId is Readonly - its not possible
3.) DependencyObjects and DependencyProperties seem also promising, but I couldn't come up with an solution so far. Does someone have experience with that??
IDK how it is possible but WPF Inspector is exactly able to do what I was looking for (now I need to know how they attach to the WPF application :) ).
____OLD ANSWER____
It seems impossible to change the XAML of other programs. If the developers are "too lazy" to set the AutomationId, I've come up with a alternative solution.
The automation app iterates over all controls in the beginning, giving them unique names which are stored in a dictionary, together with their references. In case a component gets added/deleted/changed in the hierarchy, the component and their descendants get deleted in the dictionary and the app re-iterates over this sub-tree again.
in my App.cs i have the following
private static LayoutManager layoutManager;
public static LayoutManager LayoutManager
{
get { return layoutManager ?? (layoutManager = new LayoutManager()); }
set { layoutManager = value; }
}
I need to access this variable from another Library so I defined it in the App XAML so I could use Application.Current.FindResource("LayoutManager"), without having to reference the project that contains the App, because i would get a circular dependency
<Managers:LayoutManager x:Key="LayoutManager"/>
is adding an object to the resources the best option?
what are the best programming practices in such case?
The two methods are essentially the same, the difference is mainly semantic.
As for your first question, adding an entry to a resource dictionary creates a new object, and places it in a dictionary of that scope (App, window, panel, etc.), this applies to anything you place in a resource dictionary, so the real question is what to place there. Resources placed in xaml are usually used by the xaml code (or something that affects it), it usually keeps styles, animations and so forth. You can, of course place anything you like there, but it's less common.
As for the best practice for this situation, I think you'll do better to place the object in a static property, since you try to access it in c#, and not in xaml. It gives you a little performance boost then trying to locate the resource, and you don't have to rely on magic strings, that won't give you a compile time error when if the property changes.
Okay so i'm newbie programmer creating a little game/application just for fun in c# in visual studio 2010 using windows forms. Its a "Youtube Tycoon" and i want the player to be able to create multiple videos in the application and wondering whats the best way to go about this. I created a little console window version that just used several arrays but i wanted it to be more sophisticated.
So I have a class that has a few properties like a name and amount of views and weather its released or in production and I want the user to be able to create multiple versions of this.
Any pointers on the best way to achieve this? As i said i'm quite new to this so simple informative answers would be greatly appreciated.
Thanks in advance.
I think that you want to create multiple video objects when you say versions? As in:
var video1 = new YouTubeVideo("Some video title");
var video2 = new YouTubeVideo("Some other title");
That's how you do it. To keep track of all videos, you can keep them in collection classes like List<T>.
You can do it as:
var myVideos = new List<YouTubeVideo>();
myVideos.Add(new YouTubeVideo("Some video title"));
myVideos.Add(new YouTubeVideo("Some other title"));
The collection classes work just like arrays, but are a bit more flexible (as they can grow and shrink in size). They manage an array internally.
To remove a video you can just do:
myVideos.Remove(avideo);
and to fetch one:
var secondVideo = myVideos[1]; // <-- get the second video, as indexing starts with zero.
There are also something called LINQ which can be used to query collections:
var otherVideo = myVideos
.Where(video => video.Title.Contains("other")) // go through all videos and search for "other" in the title
.FirstOrDefault(); //return the first match or null
The best thing I can suggest in this case, since you are new to programming, is to read up on Object-Oriented programming. Here are some links to get you started:
Object-Oriented Programming (C# and Visual Basic)
Object-Oriented Concepts in C#
Once you command an understand (if only basic to begin with) of object oriented programming, you should be able to solve this question yourself.
I am having a problem overriding the GetHeight method when developing an iPad application with MonoTouch.Dialog. I am implementing IElementSizing but my GetHeight method never gets called.
Has anyone else ran into this problem? Thanks.
I made sure that my root.UnevenRows = true;
I also tried including the dialog project and placing a breakpoint in the GetHeight() for any of the Elements that implement IElementSizing with no luck. In a previous iPhone project this worked fine but on the iPad I am still stuck. Are there any other 'gotchas' that I could be missing?
This is sort of a bug in MonoTouch.Dialog. Basically, when you assign the Root Element it wants to know whether there are uneven rows so it can create and cache the appropriate UITableViewSource object.
However, if you add Sections with Elements that implement IElementSizing to the Root element after the Source object has already been created. Then it will not call your GetHeight override. An example of this is if you fetch data async and callback and add the resulting Sections / Elements to to the RootElement...or essentially anytime you add Sections / Elements after PrepareRoot() is called.
There is a simple workaround for this:
this.Root.UnevenRows = true;
Without looking at your code however, I cannot say if this is the bug you are seeing.