|
Aaron,
I've spent the entire weekend updating XAML Power Toys for Silverlight and just published it.
I'll hop on this Monday after work.
I'm just plain beat and brain is out of gas.
I need my creative gas tank full to give you a solution that is not hacky.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Perhaps you can use a valueconverter (erm.. somewhere)
|
|
|
|
|
Aaron,
I've spent and hour got it to work but it had an unexpected behavior.
So I'm retemplating the ComboBox to support this. I had to download Blend to do this. Should be another hour or so.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Below are two solutions. One when the ComboBox ItemSource is data bound. The second when the ComboBox items are added in-line.
You can thank Code Project MVP Josh Smith for this solution. He is the real, "Man" and Mr. WPF.
Josh's blog: http://joshsmithonwpf.wordpress.com/
<!-- Use this when data binding your items source-->
<ComboBox ItemsSource="{Binding}" Width="100" VerticalAlignment="Center">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{TemplateBinding Content}"
TextTrimming="CharacterEllipsis"
TextWrapping="NoWrap" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<!-- Use this when adding items in-line to your ComboBox-->
<ComboBox Width="100" VerticalAlignment="Center" SelectedIndex="0">
<ComboBox.Resources>
<Style TargetType="ComboBoxItem">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{TemplateBinding Content}"
TextTrimming="CharacterEllipsis"/>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</ComboBox.Resources>
<ComboBoxItem>Greetings from the planet known as Earth</ComboBoxItem>
<ComboBoxItem>Thanks to Josh Smith for this tip!</ComboBoxItem>
</ComboBox>
Cheers, Karl
» CodeProject 2008 MVP
My Blog | Mole's Home Page |
XAML Power Toys Home Page
Just a grain of sand on the worlds beaches.
-- modified 27-Feb-21 21:01pm.
|
|
|
|
|
I was just checking up on your blog. Good stuff. I really appreciate your help with this. I had a little bit of both in my attempts, I just could never get the right "combo". Thanks again.
|
|
|
|
|
Anytime.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
I face an error at my aspx page i.e. Element 'ScriptManager' is not a known element. This can occur if there is a compilation error in the Web site.
Even I installed AjaxToolkit and ScriptManager Tool is in my ToolBox.
Pls Support
Gautam
|
|
|
|
|
Your post title tells you that this is the wrong forum. Try the ASP.NET forum instead.
|
|
|
|
|
You should post in the ASP.NET forum.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
I haven't tried to embed a WinForm control in a WPF application until now, so I may not be doing this right. When I create the WindowsFormsHost and add the WinForm control (the TextEditorControl from SharpDevelop) I cannot programmatically assign the keyboard focus to the WinForm control.
First I tried using the Focus() method on the control itself and on its text area. I never see the cursor blinking and keyboard input is ignored.
Then I used interop to pull in the user32.dll function, SetFocus(HWND) which when called with the control's text area Handle makes the cursor blink in the control, but keyboard input is still ignored.
I created a subclass of WindowsFormsHost so that I could set some breakpoints on the various On*Focus methods. The only thing that I can see is that OnLostKeyboardFocus is called when I manually click on the text editor control, but the KeyboardFocusChangedEventArgs.NewFocus argument is null, which means the new control is not recognized by WPF. That makes perfect sense since the control receiving the keyboard focus is a WinForms control.
So, any thoughts? Has anyone ever encounter this problem before? I have been searching on Google for hours and have not come up with anything.
Thanks!
Paul
|
|
|
|
|
Here's a little more information:
If I create a subclass of WindowsFormsHost and override the OnKeyboardGotFocus method like this:
[DllImport( "user32.dll" )]
private static extern IntPtr SetFocus( IntPtr hWnd );
protected override void OnGotKeyboardFocus( KeyboardFocusChangedEventArgs e )
{
base.OnGotKeyboardFocus( e );
SetFocus( editor.ActiveTextAreaControl.TextArea.Handle );
}
I can direct the keyboard focus to the editor control, but the cursor never appears. If I override OnGotFocus in the same way, I can see the cursor blinking but the keyboard focus doesn't change. If I override both, I get the keyboard focus but no cursor.
Paul
|
|
|
|
|
If you can give me a small ready-to-run sample I might be able to help you. We have lots of Winforms/Wpf interaction and I remember that it was quite a challenge to get the focus right. You might want to try to set the focus to your element via a dispatcher like so:
Dispatcher.Invoke(new Action(() => Focus()), System.Windows.Threading.DispatcherPriority.Background);
this might also help:
http://geekswithblogs.net/rakker/archive/2007/07/27/114232.aspx[^]
|
|
|
|
|
Is there a control anywhere that is similar to the page that you see when you make a new message on this website?
|
|
|
|
|
Ummmm, is this WPF related at all?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
I would like to bind the SelectedIndex property of ComboBox to a property that is defined in my class that extends the Window class. It is hard to explain what exactly I want, so I will try to explain it with a simple example:
here is my .xaml code:
<Window x:Class="WpfApplication3.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ComboBox Grid.Row="0" x:Name="cmbSource" SelectionChanged="cmbSource_SelectionChanged">
<ComboBox.Items>
<ComboBoxItem> 1 </ComboBoxItem>
<ComboBoxItem> 2 </ComboBoxItem>
</ComboBox.Items>
</ComboBox>
<ComboBox Grid.Row="1" x:Name="cmbDestination" SelectedIndex="{Binding ElementName=Item, Path=Index}"> <!-- this doesn't work -->
<ComboBox.Items>
<ComboBoxItem>Item 1</ComboBoxItem>
<ComboBoxItem>Item 2</ComboBoxItem>
</ComboBox.Items>
</ComboBox>
</Grid>
</Window>
and here is my code-behind code:
namespace WpfApplication3
{
public partial class Window1 : Window
{
private Test _item;
public Test Item
{
get{return this._item;}
set{this._item = value;}
}
public Window1()
{
InitializeComponent();
}
private void cmbSource_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Item = new Test(cmbSource.SelectedIndex);
}
}
public class Test
{
private int _index;
public int Index
{
get { return this._index; }
set { this._index = value; }
}
public Test(int index)
{
Index = index;
}
}
}
When I was tring to solve this problem, I extended my Window1 class so it implements INotifyPropertyChanged interface, than I extended the Test class the same way, but nothing works. I even tried to define the Item Property as a DependencyProperty, but that didn't work either. Any idea will be appreciated.
thanks
Uros
|
|
|
|
|
You need to change your "Binding ElementName=Item, Path=Index"
First, add a x:Name property to your Window.
Then change the ElementName to the Window.Name property value.
Then change the Path to Item.Index
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Yes that solved my problem. Thank you,
Uros
|
|
|
|
|
Hi i have a simple text box in window. I just want to write a simple validation for the text box.
If there is nothing in the text box it should show a validation error. or else nothing.
Can any one please provide the code for this.. Full XAML file. and Cs file
Santhapur
|
|
|
|
|
Santhapur wrote: Can any one please provide the code for this.. Full XAML file. and Cs file
That's not the way this site works you know. We don't actually write your code for you.
|
|
|
|
|
Thanks for your Reply. I have asked u the full code b/c previously some one posted code snippet and its not working.. So i am not able to find where the error was..
I am not going to earn money with u r code.. i am still in learning stage.
Pete O'Hanlon wrote: That's not the way this site works you know. We don't actually write your code for you.
|
|
|
|
|
Asking for full code breaches the spirit of the site - and you'll get short shrift for it. We give you help, and pointers, we don't write the code. If you're given a snippet and it doesn't work, reply to the poster and ask for clarification - that's the normal etiquette. You'll see that most of the solutions in the forums, are in the form of snippets or advice on where to look. That's just the way it is - because you will learn best by actually solving the problem for yourself.
|
|
|
|
|
Here is what i have tried..
<Window x:Class="TextBoxValidation.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:y="http://schemas.microsoft.com/winfx/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<TextBox>
<TextBox.Text>
<Binding.ValidationRules>
<local:MatchRule MatchText="Hello" />
</Binding.ValidationRules>
</TextBox.Text>
</TextBox>
</Grid>
</Window>
namespace TextBoxValidation
{
class validatetextbox : ValidationRule
{
public string MatchText { get; set; }
public override ValidationResult Validate(object value,
CultureInfo info)
{
if ((string)value == MatchText)
return new ValidationResult(true, null);
return new ValidationResult(false, "This is not a match");
}
}
}
Here are my results..
http://schemas.microsoft.com/winfx/2006/xaml/presentation'. Line 9 Position 18
|
|
|
|
|
Well, the first thing I can see is that you've called the class validatetextbox , but it's referred to as MatchRule . Rename the class to MatchRule . Also, I don't see a reference to xmlns:local in the Window declaration.
|
|
|
|
|
xmlns:local="clr-namespace:TextBoxValidation"
<local:validatetextbox MatchText="Hello" />
I have included these two line but still getting the same error
|
|
|
|
|
The reason you are getting this error is because you haven't specified valid XAML code. Basically, you want to change your XAML so that you are binding your textbox to something, and set your validation rule on it like so:
<TextBox>
<Binding Path="Name">
<Binding.ValidationRules>
<local:MatchRule MatchText="Hello" />
</Binding.ValidationRules>
</Binding>
</TextBox> Take a look at this[^] article for a detailed example.
|
|
|
|