1. Is there a simple way to react to a RETURN input within a TextBox, say for a simple chat box? As there are no behaviors the only way I see right now is to parse the bound property for a LineBreak, after allowing the TextBox to accept enter. Is there a better way?
I would create a ChatBox UserControl which manages the text box and list of messages as you want. Then you can use that chat box anywhere. To check for a Return key press, you just add a handler to the KeyDown event of the chat TextBox in the user control code behind. You can continue using MVVM with UserControls, you just have to set your ViewModel on the control and use bindings from the view model.
2. Another thing where I'm not sure how to implement it is how to scroll to the end of a TextBox or ListBox without behaviors. Sure, I could attach a code behind within Unity but that's not really a good option when there are too many elements around that would all need a 'code behind' file.
I don't understand what exactly what you are asking for. Maybe you are talking of making visible a certain message within the chat box. If that is the case, you can use the method BringIntoView().
3. What is the best way to change the color of a ProgressBar depending on the value without being able to use a ValueConverter? Let's say I have a range from 0 to 100 and I want the color to be red when it's under 20 and yellow when it's between 21 and 40. Otherwise it would be green. Now I want a smooth animation of the progress and the color change (the interpolation itself isn't the problem). Can you give me any hints?
You can have in your ViewModel the Value of the ProgressBar, and calculate the color based on this value. Then you expose in the ViewModel that calculated color (Brush) and you bind it to the ProgressBar (for example to the Foreground property, and have a template that uses Foreground as the color for the PART_Indicator element).
4. With the implementation of inline formatting that you mentioned in another thread will it also be possible to use icons/symbols?
Only icons/symbols defined in a font file, so they would be monochrome, as any other character you write.
5. When I were implementing my draggable window I had trouble when the mouse left the control (because the mouse pointer moves too fast) as it would stop receiving the appropriate events and thus stop dragging the window. Usually I would use CaptureMouse() / ReleaseMouseCapture() to get around this problem. But somehow I don't receive any events any more after calling CaptureMouse(). Is this a bug or am I doing something wrong?
You should be able to capture mouse events by calling CaptureMouse(). If this is failing for you, please create a bug report in our bugtracker and attach a test to reproduce it, we will take a look and help you with it.
6. For testing purposes I implemented a timer in a VM with an interval of 250ms. Now when I press Play within the Unity Editor it also starts the timer and everything seems to work as expected. But the problem begins when I stop the editor as the timer continues to run.
I tried then overriding the Dispose() method of the VM (inherited from SerializableComponent) but Dispose() was only called when Unity had to recompile a script. On the other hand it calls Dispose() by stopping the editor when the timer isn't running.
I don't know if you are keeping references to your VM in any script component, but you should know that Unity doesn't delete script components immediately. You can use OnDestroy() message to reset references to the VM before you stop playing.
Oh, and when I override the Dispose() method and stop the editor while the timer is still running it will open five "Unhandled Noesis Exceptions!" (Access Violation - Noesis.dll!BaseExpression_GetEvaluateBehavior) and just crash Unity.
Please report this bug in the bugtracker. We want to fix any possible crash our customers find in NoesisGUI.
7. I turned the Noesis-logging to a file on so I get a file NoesisGUI.play.log. Unfortunately it keeps telling me that even the simplest bindings fail, even though they work when I run the scene.
Maybe the binding fails when xaml is loaded and initialized, but it is solved when ViewModel is set. Could this be what you are experiencing?
8. Sometimes Unity keeps constantly re-aquiring the focus. The solution is to click into the "Game" view within Unity and then I can focus other windows outside of Unity again. This has probably something to do with Noesis as I never experienced this before using Noesis.
NoesisGUI uses Unity's OnApplicationFocus() message to enable/disable input events. Unity calls this message with a false param any time you click outside the Game view inside the editor. And calls it again with a false param only when Game view is clicked again.
9. When I create a ProgressBar with no width set and apply an animation to increase it's current value to the max value it will change the value to max and then increase the width of the ProgressBar to 'infinite'.
Could you attach the xaml here? Any UI element normally adapts to the space that its parent container reserves for it.
10. Another problem with the ProgressBar. When I try to animate the value change by reacting to an EventTrigger called "RangeBase.ValueChanged" it doesn't work properly. It works in WPF though. It seems to react to the trigger the first time it's called and it looks like it has something to do with the To-property of an animation being bound to a value. I'll give you a very simple example.
<ProgressBar Value="{Binding Value}" Maximum="100" Width="100">
<ProgressBar.Triggers>
<EventTrigger RoutedEvent="RangeBase.ValueChanged">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Duration="0:0:0.2" Storyboard.TargetProperty="Value" To="{Binding Value}" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ProgressBar.Triggers>
</ProgressBar>
This problem is already reported. There is a bug in our code that makes bindings in Freezable elements (as the DoubleAnimation in your example) don't work when Binding.Source is DataContext. Maybe you can use a binding to a named element as a workaround until we fix it.
11. I have a value bound to the SelectedItem-Property of a ListBox. Now when I select an item in the UI the setter of the property is called twice.
12. ListBox: I have to explicitely state that the SelectedItem-Property is bound to a value using a TwoWay-binding otherwise it doesn't work.
13. And the ListBox again: When I assign an item to SelectedItem within the constructor of a ViewModel it won't work as after leaving the constructor null will be assigned again. Also OnPostInit() doesn' work on ViewModels so right now there doesn't seem to be a way around this problem.
I will take a look at these issues and let you know. It would be better if you report it in the bugtracker to follow the status of these issues.
14. Can I apply the Extended-Attribute only to non-generic classes? Are there any plans to change that?
We have plans to improve C# API so it can use .NET default classes, so it would be easier for people coming from WPF world to work with NoesisGUI. Now our API is still very tied to the native C++ code and their classes.
15. I'm not able get nested property-bindings working even though everything is inherited from BaseComponent. A simple example: I have a collection with characters bound to a ListBox. When I select an item it will also set the value of the SelectedCharacter-property of the ViewModel. Until there everything is working. But when I try to bind to a property of the SelectedCharacter the binding doesn't seem to work.
<TextBlock Text={Binding SelectedCharacter.Name} />
I created the following simple xaml:
<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<TextBlock Text="{Binding SelectedCharacter.Name}"/>
</Grid>
With the following code behind script attached to the NoesisGUIPanel:
using UnityEngine;
using System;
using Noesis;
[Extended]
class SelectedCharacter : BaseComponent
{
string _name;
public string Name
{
get
{
return _name;
}
set
{
if (_name != value)
{
_name = value;
NotifyPropertyChanged("Name");
}
}
}
}
[Extended]
class MyViewModel : BaseComponent
{
SelectedCharacter _selectedCharacter;
public SelectedCharacter SelectedCharacter
{
get
{
return _selectedCharacter;
}
set
{
if (_selectedCharacter != value)
{
_selectedCharacter = value;
NotifyPropertyChanged("SelectedCharacter");
}
}
}
}
public class _Test : MonoBehaviour
{
void Start()
{
var gui = GetComponent<NoesisGUIPanel>();
var root = gui.GetRoot<Grid>();
MyViewModel viewModel = new MyViewModel
{
SelectedCharacter = new SelectedCharacter { Name = "Peter" }
};
root.SetDataContext(viewModel);
}
}
And it worked correctly. Could you attach an excerpt of your sample that is failing?
16. I have also trouble with the binding when I fill the content of my DraggableWindow. Could you give me a simple example of a self-made UserControl that I can apply content to where the binding still works, please?
Ok, here you have the xaml & code of a sample window control:
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WindowControl">
<StackPanel>
<Border Background="SkyBlue" CornerRadius="2,2,0,0" Padding="20,1">
<TextBlock Text="{Binding Title}" Foreground="White" FontWeight="Bold" FontSize="20" HorizontalAlignment="Center"/>
</Border>
<Border BorderBrush="SkyBlue" BorderThickness="2,0,2,2" Background="#80DFEFFF" CornerRadius="0,0,2,2" Padding="5">
<ContentPresenter Content="{Binding Child}"/>
</Border>
</StackPanel>
</UserControl>
[Extended]
[UserControlSource("Assets/Sample/WindowControl.xaml")]
public class WindowControl : Noesis.UserControl
{
string _title;
public string Title
{
get
{
return _title;
}
set
{
if (_title != value)
{
_title = value;
NotifyPropertyChanged("Title");
}
}
}
Noesis.BaseComponent _child;
public Noesis.BaseComponent Child
{
get
{
return _child;
}
set
{
if (_child != value)
{
_child = value;
NotifyPropertyChanged("Child");
}
}
}
public WindowControl()
{
SetDataContext(this);
}
}
And you can use this user control in another xaml like this:
<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<WindowControl Title="Some window" HorizontalAlignment="Center" VerticalAlignment="Center">
<WindowControl.Child>
<StackPanel>
<TextBlock Text="Some text in the window" Margin="0,0,0,10"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Button Content="OK" Width="100"/>
<Button Content="Cancel" Width="100" Margin="8,0,0,0"/>
</StackPanel>
</StackPanel>
</WindowControl.Child>
</WindowControl>
</Grid>