Showing posts with label Technical Artist. Show all posts
Showing posts with label Technical Artist. Show all posts

Wednesday, April 30, 2014

Some WPF Treeview Tips/Tricks

T.StartPost();

Hey everyone/anyone reading, been a long while but I have just been quite busy with my internship and being a tools code monkey :D  It's been pretty fun, interesting and at times, VERY FRUSTRATING.

Now anyone that has done WPF has probably run into any number of things that wants to make you pull your hair out and flip some tables onto small children, but after many hours searching and trying different things I've come across somethings that are VERY VERY handy for tools in WPF. I'll probably just update this post as I come across more to keep them all in once place but for starters, here is a few things that I've learned to make dealing with the dreaded and yet very powerful TreeView.

WPF TreeView is probably the best and the most frustrating thing I've had to deal with on a constant basis in the last few months; it's so handy for presenting data in a hierarchical way but there are things that you just can't do directly with TreeView without searching and searching and searching the internet to find the answers to such as:


  • How can I force TreeView to change the SelectedItem?
          Now this I will say has stunned me for a while and I actually JUST found the answer to this problem Here on Stack Overflow.  So what are we to do here? Well if you're lucky enough to have your project presenting with a inherited model (cause you should be at least using the MVVM programming pattern while doing WPF tools) for your data then you can do this quite easily.  You need about 2-3 things,
1. Keep track of your selectedItem via clicks/keyboard navigation 
2. Add to your base model type, a property like 
        private bool _isSelected;
        public bool IsSelected { get { return _isSelected; } set { Set(ref _isSelected, value); } }
    *NOTE* the Set is just raising INotifyPropertyChanged so how ever you are handling yours is how you should do it here as well *NOTE*
3. In your treeview, you'll need to have at least this line from the link
<Setter Property="IsSelected"
                        Value="{Binding IsSelected, Mode=TwoWay}" />
What this is going to do is allow you to toggle IsSelected in your data Model and since the treeview is bound to it, it will automatically set and be set to IsSelected.  Now some people may think, "Why wouldn't you just do it in code behind or something like that?"  Well that's because IsSelected is a read-only property, so you can't just set it all willy-nilly like that and from all the proposed ways I've seen so far, this is the easiest to setup.

This also goes for being able to select what IS and ISN'T expanded in your treeview programmatically, make a property and bind with the Setter in your treeview.

Search Results




  • How to implement a simple and easy to use Search Filter for your TreeView
Searchable WPF TreeView on Code Project
Thankfully, Already made a great article on this. If you don't need/want the super fancy search box (was a bit overkill for what I needed) then the really relevant parts of the article are having some more setter properties in your Treeview for

<Setter Property="IsExpanded" Value="{Binding Path=IsExpanded, Mode=TwoWay}" />
                <Setter Property="Visibility" Value="{Binding Path=IsMatch, Mode=OneWay, Converter={StaticResource ResourceKey=boolToVisibility}}"/>
This lets you setup your TreeView to work with a method that you will call in your code that will search through your Data (that is bound to the tree) and set Expanded to true/false and Visibility to true/false as well which will effectively hide anything that doesn't match your results in your textbox and expand open to the result, anything that does match. Much like the IsSelected above, you'll add the IsExpanded and IsMatch(I did IsVisible myself) to your data Model.

The next important piece of code that you will need is this
public void ApplyCriteria(string criteria, Stack<TreeNodeViewModel> ancestors) {
    if (IsCriteriaMatched(criteria)) {
        IsMatch = true;
        foreach (var ancestor in ancestors) {
            ancestor.IsMatch = true;
            ancestor.IsExpanded = !String.IsNullOrEmpty(criteria);
        }
    } 
    else
        IsMatch = false;

    ancestors.Push(this);
    foreach (var child in Children)
        child.ApplyCriteria(criteria, ancestors);

    ancestors.Pop();
}
        
The method that determines if this node is a match is in this article a simple string comparison;
private bool IsCriteriaMatched(string criteria) {
    return String.IsNullOrEmpty(criteria) || name.Contains(criteria);
}
The methods will check for anything matching the searchText you give it (I hooked up an extra method from my codebehind that when the text changes in my textbox, call the method which passes the text to the Apply Criteria.) and expand or hide accordingly.

*NOTE* if you want to make the search just a bit more functional change the IsCriteriaMatched to
name.ToLower().Contains(criteria.ToLower());  This will make it that no matter if you have say Matilda or matilda, it will still show up if you gave the search box MaTilDa for example *NOTE*

The only change to this method that I really made was that I also pass the current node you're checking so you can get the name of the node like


private bool IsCriteriaMatched(string criteria, NodeWithName check)
{
    return String.IsNullOrEmpty(criteria) || check.Name.ToLower().Contains(criteria.ToLower());
}

The only part left is in your WPF you have a textbox and choose whether you want it live filtering (as the user types it filters) or keypress filtering (hit enter, it does the search) and make sure that you save/bind to the textbox text in a viewmodel (pretty much the same place you do the above search methods is as good a place as any)

Those are the two biggest things that I've run into and it's taken a while to find good working answers to (I've never used the Setter myself before this so it was a good experience to learn that I could bind to it).

Hopefully people stumble across this post and find these answers instead of searching for a long time.

T.Out();

Saturday, November 10, 2012

Time for an Update

T.StartPost();

Well it's been a while since I did a post (sorry, been busy with school and some side projects) so here's an update for things that I've been doing recently.

In school I've been learning more about normal mapping and making good normal maps. The first project we had to work on was just texturing a pre-made hatch after we baked the normal map and diffuse map from it (Diffuse maps make it easier to select pieces from a model as they are baked out with the colors, so you can just select the color pieces you want to work on in Photoshop).

I ended up with this. So it's a concrete door (obviously would have hydraulic assist from the inside for lifting the door) and it's been open to the weather for a while



Next off we had to make some sci fi style props, A floor, wall and roof tile. Out of the three I did I like how my floors turn out the best so here's a viewport grab of it with the Xoliul Viewport Shader.
Basically the topic was sci fi for the new DAE building called The Level and I figured what better way to have a call out to gaming for floors than to have D-Pad style floors.


















Next thing we had to do was make 2 more props, same style but a simple and a complex one. My simple prop was stairs, not staircase in it's whole, but just the steps. This is what I came up with, this is a grab from UDK.




















So this next one is the "complex" prop which was a sci fi Computer. I decided to make a projection style computer that would project from the red ball in the middle onto the screen between the 4 corners. The corners can be tilted like any regular screen as well. 


































And finally, this is just me doing some concepting for the Chainsaw Katana project that I somewhat started a while back (but decided the original drawing I was going to go off of wasn't that great...so I'm making my own concept for it now).

This is just the hilt, but the throttle for controlling the chainsaw speed. I've thought about doing it more of like a gun trigger as well (which most chainsaw's are in) but thought this would look a bit more clean and neat when actually modeled. So it's more up the alley for a motorbike throttle, this would be the one turn able part on the hilt while the rest is quite static. Either way, it's a WIP.


Thanks for reading, hopefully I will update a bit more instead of so sporadically...

T.Out();

Sunday, May 27, 2012

T.StartBlog();

Hey there reader,

So, this is my first blog post (of hopefully which there will be more if I can find the time between school, work and and schoolwork). Right now I don't have a lot to post about so I guess I'll start with the

WHO IS THIS GUY?!

Well my name is Travis Evashkevich (as you can probably tell from my profile) and I am originally from a little middle of no where town in Alberta, Canada but was also living in Fort Mcmurray, Canada for the last few years of my high schooling days as well as for a few years of working after I graduated. Currently I'm bouncing back and forth between another small-ish town Kortrijk, Belgium for school and Fort Mcmurray for work during my summers.

I'm going to school for being a Technical Artist with a major of Game Development ( basically in our school it means that I do programming and 3D but less emphasis on the art related stuff, 3D still must look good but not much on the pre drafting and drawing stuff).

So I guess I'll probably be posting tid bits for helping other people (maybe some tutorials on 3D or c++ or maybe a few simple shaders in HLSL could be fun) or just to showcase stuff I make.

So, there's  my quick recent relevant history and hopefully the next little while (during exams might be tough) I'll get some more posts rolling here.

T.Out();