|
Hello,
I have a textBox which has binding to a property of a ViewModel.
I want the ViewModel to execute a method if the textbox is not empty and if user didn't change the text in the textbox for 2 seconds. I mean only if user wrote something and waited for 2 seconds, than the method will execute. How can i do it?
|
|
|
|
|
Have a timer in the VM
Have the onchange event in the model for the field reset the timer (and clear the cache string, possibly)
In the tick method check the content of the field if != string.empty and matches the cached string then call your method
Cache the string
Onchange of the selected item always clear the cache string
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Sounds like too much work. When he adds a 2nd edit box / timer, he'll have to copy & paste all that crap. Better solution would be to write a "TextBoxEx" control that encapsulates the behavior so it is easier to reuse and you don't have to dick around with forwarding a bunch of stuff to the VM.
|
|
|
|
|
SledgeHammer01 wrote: When he adds a 2nd edit box / timer
Only applies if this rather esoteric requirement needs to be duplicated, but yes I think I'd do with the textboxex out of good design principles (never write code twice)
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
How do you make an image NOT grow depending on the size of the picture. I'v tried all 4 Stretch values and as soon as I set the source, the image control changes size.
I want the actual size of the image control to be determined by the height & width of its grid cell. The cell's Height & Width are both Auto.
Thanks
Everything makes sense in someone's mind
modified 28-Mar-12 17:26pm.
|
|
|
|
|
That's what I thought. When I try this, the image doesn't appear
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto" Name="PictureGridRow"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" Name="PictureGridColumn" />
</Grid.ColumnDefinitions>
<Image Source="{Binding SelectedImage.Image}"
Height="{Binding ElementName=PictureGridRow, Path='ActualHeight}"
Width="{Binding ElementName=PictureGridColumn, Path='ActualWidth'}"
Grid.Row="1"
Grid.Column="0"
Stretch="None"/>
Also, I added this:
<Label Content="{Binding ElementName=PictureGridRow, Path='ActualHeight'}"
Grid.Row="0"
Grid.Column="0" />
It shows 0.
Everything makes sense in someone's mind
|
|
|
|
|
Oh... that grid. I thought you were talking about a different grid. Your issue here is that there is no content, so it doesn't know what to size it to. What size do you want the row & column to be? Everything there is auto and as such will be sized to the content.
|
|
|
|
|
This grid is to the left of a splitter, so what I'd like is a square image who's side are equal to the width of the grid. This should be the same as the Left value of the splitter.
Everything makes sense in someone's mind
|
|
|
|
|
In my opinion reason is Binding.
<Image Source="{Binding SelectedImage.Image}"
Where do you've definition SelectedImage? Example in other file than MainWindow.xaml.cs
<xlms:local="clr-namespace:ExampleXAML.ImageViewModel>
<Grid>
<Grid.DataContext>
<local:SelectedImageViewModel>
</Grid.DataContext>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto" Name="PictureGridRow"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" Name="PictureGridColumn" />
</Grid.ColumnDefinitions>
<Image Source="{Binding SelectedImage.Image}"
Height="{Binding ElementName=PictureGridRow, Path='ActualHeight}"
Width="{Binding ElementName=PictureGridColumn, Path='ActualWidth'}"
Grid.Row="1"
Grid.Column="0"
Stretch="None"/>
</Grid>
|
|
|
|
|
When you see this
ItemsSource="{Binding}"
What is this bound to?
Everything makes sense in someone's mind
|
|
|
|
|
The DataContext for that container.
|
|
|
|
|
Ya, but to which property?
Everything makes sense in someone's mind
|
|
|
|
|
|
I havn't see this syntax before. I'v always seen bindings point to a property name.
Ok, so when you have
ItemSource="{Binding}"
then the list is bound to the entire class. Then it's up to the template to bind individual elements to properties on the class.
Do I have this right?
Everything makes sense in someone's mind
|
|
|
|
|
You don't generally do that on ItemsSource since it doesn't really make sense since ItemsSource has to point to a collection. If your VM itself is a collection then it will work. Generally you use it in a template, or maybe a parameter. Its basically for when you want to point to the entire object itself. So if your items source is List<Widget>,then in the data template, {Binding} will point to the entire Widget.
|
|
|
|
|
I understand. I did however get that example from a MS sample app.
Everything makes sense in someone's mind
|
|
|
|
|
Then the DataContext of the control points to something that implements IEnumerable.
|
|
|
|
|
The splitter move ok, but only the right area is resized. The list in the left area is not resized.
Anyone?
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<ListView Background="LightGreen"
Grid.Row="1"
Grid.Column="0" />
<GridSplitter Grid.Row="1"
Grid.Column="1"
VerticalAlignment="Stretch"
BackGround="SlateBlue"
Width="10"/>
<Border Grid.Row="1"
Grid.Column="2"
Background="LightBlue"/>
</Grid>
Everything makes sense in someone's mind
|
|
|
|
|
Remove the Width from the splitter; change the ColumnDefinitions as per below ...
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="10"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<ListView Background="LightGreen"
Grid.Row="1"
Grid.Column="0" />
<GridSplitter Grid.Row="1"
Grid.Column="1"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Background="SlateBlue" />
<Border Grid.Row="1"
Grid.Column="2"
Background="LightBlue" />
</Grid>
|
|
|
|
|
I've successfully bound two strings to a list, but am having trouble figuring out how to bind text with 2 radio buttons properly.
I have a zone array of 8 bytes, that holds On/Off values of the zone. There are 64 zones, thus the 8 bytes. So, bit 0 of byte 0 is '1', if the zone is ON, '0' if OFF.
I have limited space in a Grid, so I want to use a List or some other control that has automatic scrolling.
Something like:
Zone 1 ON<rb> OFF<rb>
Zone 2 ON<rb> OFF<rb>
.
.
Zone 63 ON<rb> OFF<rb>
Zone 64 ON<rb> OFF<rb>
I don't need any NotifyPropertyChanges, because when the user clicks on the SAVE button, the 8 bytes get resaved with the current settings.
I tried some things as I did before with string binding (see code), but this syntax isn't correct, and I don't know if I'm doing it correctly for Radio Buttons. Or maybe a list isn't the correct control.
List<ZoneEntry> zentry = new List<ZoneEntry>
public class ZoneEntry
{
public string ZoneNum { get; set; }
public RadioButton ZoneOff;
public RadioButton ZoneOn;
}
void CreateZoneTable()
{
for (byte i = 0; i < 64; i++)
{
zentry.Add(new ZoneEntry()
{
ZoneNum = "Zone " + (i + 1),
ZoneOff = ???
ZoneOn = ???
});
}
ZoneTable.ItemsSource = zentry;
}
<DataGrid Grid.Column="0" Grid.Row="1" Height="150" Width="300"
CanUserAddRows="false"
AutoGenerateColumns ="false"
HorizontalAlignment="Left"
RowHeight ="20"
Margin="15,10,0,0"
VerticalAlignment="Top"
Name="ZoneTable"
CanUserSortColumns="False"
CanUserResizeColumns="False"
CanUserReorderColumns="False"
CanUserResizeRows="False"
SelectionUnit="Cell">
<DataGrid.Columns>
<DataGridTextColumn Header = "Zone #"
Width = "SizeToHeader"
Binding = "{Binding ZoneNum}"
IsReadOnly="true"/>
<DataGridTextColumn Header = "Zone Setting"
Binding = "{Binding ZoneOn}"
Binding = "{Binding ZoneOff}"
Width="*"/>
</DataGrid.Columns>
</DataGrid>
What I want to do is set the RB to checked, if the proper zone[i] byte and bit is set to '1' when the table loads. When the user clicks SAVE, the values from zentry are converted back into the zone[i] array.
The WPF binding isn't right, because I don't know how to bind 2 RB under the same column.
Any help on the simplest approach or corrections/additions to the above?
Thanks.
Sutton
|
|
|
|
|
I'm making a model of human anatomy . there is about 2100 mesh and model. I used Helix 3d toolkit to import all files into a scene but that takes a long time to import (about 20 second) and scroll and rotations are slow. and that takes 800 meg of RAM.
objects are optimized and the sum of vertics must be less that 2 million.
i don't need shadows or any special effect. but i need scroll , zoom , hit testing and ..
what format should i use for saving models? i think .obj files are slow. should i use 3ds? or xaml?
should i use 2000 modelvisual3d or one with 2000 Geometrymodel3d ?
or should i use XNA?
can i disable some features to speed things up ?
tnx
|
|
|
|
|
Wow, you're really straining what WPF can cope with here. If I were you, I'd look to do this with XNA.
|
|
|
|
|
In a small Wpf application, use a DatePicker bound to a DateTime property.
When the user's region and language settings, and number and date format are German, the date is displayed in German, and the calendar shows German month names.
Now I wanted to get it in US-English. In the c'tor of MainWindow I added before InitializeComponent() (same situation when doing that after InitializeComponent() ):
string uiLanguage = ConfigurationManager.AppSettings["UILanguage"];
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(uiLanguage);
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(uiLanguage)));
While that works with textboxes, it has no effect with the DatePicker.
Then I was cheaky and created a new user "John English", logged in as "John English", set his display language to English and the date and number format to US-English. Now the DatePicker always displays the date in the US-English format and the calendar shows English month names, even when I set the language of my program to German.
How can that be resolved? Can it be resolved at all?
|
|
|
|
|
|
Thanks for coming back and supplying the answer 5
Never underestimate the power of human stupidity
RAH
|
|
|
|