|
Not sure ALL the pistons are firing yet!
I liked this article on how a humble listbox can be completely changed in appearance.
http://bea.stollnitz.com/blog/?p=40[^]
Then going back a few weeks later and understanding (most of) the code this time.
Also as Pete said lots of good WPF authors here on CP.
Same thing, might not quite understand them, but let them sink in and they make more sense on rereading.
Another thing was understanding that XAML is not some mysterious language but you can do things like just make an arraylist with integers and bind it to a listbox, very easily when you know how.
The Pro WPF book has a nice chapter on this at the start. (You might be able to find this on google books, if you don't have a copy)
<window.resources>
<sys2:arraylist x:key="myArrayList" xmlns:x="#unknown" xmlns:sys2="#unknown">
<sys:int32 xmlns:sys="#unknown">1
<sys:int32>2
<sys:int32>3
</sys:int32></sys:int32></sys:int32></sys2:arraylist>
</window.resources>
<listbox itemssource="{StaticResource myArrayList" />
Then once you learn all that WPF stuff, you goto Silverlight and find out half of the good stuff is missing. *sob*
|
|
|
|
|
When I realized updating/expanding my old MFC-based UI code was taking way to
much time and I thought "hmm....I'll take a look at WPF...".
I have Silverlight/WPF ah=ha moments several times a day...
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Ooh, another one.
I was looking at my first attempt at a WPF app, and I was thinking "Who wrote this crap? It's all done wrong!"
Stuff like updating text on controls via a loop instead of just using databinding.
|
|
|
|
|
There have been many! And many followed by a ... "oh ... I didn't expect that" but mostly "doh!", "FECK" & "Blurgh!!"
|
|
|
|
|
Hi Everyone
Im trying to do an auto complete text box control that it binded to sql .. so that when a user types in something like lets say in the database i have a table called building and in the building table i have columns like Building ID & Building Name and that will be binded to the textbox so that when i type in Micr it will give me a drop down of all the stuff i have in the database that start with "Micr". Does any one know how do to do this.. An example or idea will be very helpfull.. Thanks in advance ...
|
|
|
|
|
|
I am really hoping someone here can help me. I've been playing around with the WPF DataGrid and am having a weird problem. What I have is a TabControl with two tabs. Each tab has a DataGrid with two columns. The first column Width is "Auto" and the second column Width is "*" which should fill the remaining space in the Datagrid. What is happening is that the DataGrid in the first tab's columns are sized appropriately, but the second tab's second column is wider than it should be. Also, if I change the SelectedIndex to the second tab, it's columns are size correctly but the first tab's columns aren't. I have tried to Invalidate the DataGrid control when the selected tab changes but that didn't seem to do anything. I'm not sure how to explain this better but here is some example XAML:
<TabControl TabStripPlacement="Left"
Margin="0,0,0,0"
Background="White" Padding="0,-10,0,0"
SelectedIndex="0"
Grid.Row="1"
x:Name="TabEdit">
<TabItem Header="Tab 1">
<tk:DataGrid
AutoGenerateColumns="False"
ItemsSource="{Binding Path=Properties}"
>
<tk:DataGrid.Columns>
<tk:DataGridTextColumn
Width="Auto"
IsReadOnly="True"
Header="Property"
Binding="{Binding DisplayName}"
/>
<tk:DataGridTextColumn
Width="*"
IsReadOnly="False"
Header="Value"
Binding="{Binding AggValue, NotifyOnValidationError=True, ValidatesOnDataErrors=True}"
/>
</tk:DataGrid.Columns>
</tk:DataGrid>
</TabItem>
<TabItem Header="Tab 2">
<tk:DataGrid
AutoGenerateColumns="False"
ItemsSource="{Binding Path=Properties}"
>
<tk:DataGrid.Columns>
<tk:DataGridTextColumn
Width="Auto"
IsReadOnly="True"
Header="Property"
Binding="{Binding DisplayName}"/>
<tk:DataGridTextColumn
Width="*"
IsReadOnly="False"
Header="Value"
Binding="{Binding AggValue, NotifyOnValidationError=True, ValidatesOnDataErrors=True}"
/>
</tk:DataGrid.Columns>
</tk:DataGrid>
</TabItem>
</TabControl>
If this is not enough information, I'd be happy to answer questions.
Thanks for reading!
P.S. Sorry if the code is hard to read. I couldn't get it to work in a code block (<pre></pre>)
|
|
|
|
|
|
Great! Thanks for trying it. I'm glad it's not something really obvious that I missed at least.
|
|
|
|
|
I didn't dig into the DataGrid source code, but this workaround seems to work...
I added a SelectionChanged handler to the tab control:
private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
System.Collections.IEnumerable olditemssource = datagrid2.ItemsSource;
datagrid2.ItemsSource = null;
datagrid2.ItemsSource = olditemssource;
}
Resetting the ItemsSource on the DataGrid is the only way (I could figure out) to get
the DataGrid to re-layout its columns correctly.
That's not really a good fix though, since if the user changes the column sort order,
it won't be preserved if the tab is navigated away from and back to.
They key point is to NOT set the ItemsSource until the DataGrid's associated tab is
navigated to for the first time. I'll leave that as an exercise for you
I'm thinking this should probably be reported as a bug on the toolkit CodePlex site...
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
aalex675 wrote: I think this may already be in the bug tracker on CodePlex as issue #8842
Cool! I didn't find it when I looked. Thanks!
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I,
I'm trying to extend the Standard WPF Label control in order to be able to change it's font (underline it) if a particular condition is true.
The font change will occur in the OnItialized method like this:
protected override void OnInitialized(EventArgs e)
{
if (conditionTrue)
{
//TODO Underline it
}
base.OnInitialized(e);
}
What code should I use to underline it?
Thanks
Paolo
|
|
|
|
|
You could always use a variant of the sample I posted here[^].
|
|
|
|
|
In addition to the XAML, you can also do this:
MyTextBlock.TextDecorations = TextDecorations.Underline;
To undo the underline:
MyTextBlock.TextDecorations = null;
Hope that helps.
Blitz
|
|
|
|
|
While you can do this, one of the interesting things about applying triggers in XAML, is that (as soon as the trigger condition no longer applies), the default style is reverted to.
|
|
|
|
|
Thanks; that's good to know. Doing it in XAML, then, makes it unnecessary to set it back to the default style. I thought about doing that - but just didn't know how to do so. I am such a Blend addict
|
|
|
|
|
I need to do it in c# code
|
|
|
|
|
That was C# code. Why do you need to do it that way though?
|
|
|
|
|
I don't know what I miss, but this code
MyTextBlock.TextDecorations = TextDecorations.Underline;
gives me a compilation error.
I solved with this code:
TextDecoration td = new TextDecoration(TextDecorationLocation.Underline, new System.Windows.Media.Pen(System.Windows.Media.Brushes.Red, 1), 0, TextDecorationUnit.FontRecommended, TextDecorationUnit.
TextBox1.this.TextDecorations.Add(td);
Paolo
P.S. I'm working on an XBAP application.
|
|
|
|
|
You can still do it in XAML. XBAPs don't remove the ability to use XAML.
|
|
|
|
|
Greetings good people,
What control allows you to use "hotlink" text? It is the effect that occurs when you are surfing the internet and mouse over some text and it gets underlined since it is a link.
Any ideas on which control does this or how to do it would be greatly appreciated.
Thanks,
Blitz
|
|
|
|
|
Off the top of my head, I'm going to suggest that you will need to apply a Hyperlink to your TextBlock using a trigger.
|
|
|
|
|
Thanks, that did it. I just created MouseEnter, MouseLeave, and MouseLeftButtonDown events for the TextBlock. In the events I used TextDecorations to underline, not underline, and perform some action when clicked.
|
|
|
|
|
Sounds good - and also sounds like something you should blog about.
|
|
|
|