|
I did not get you Logical tree class? Can you please explain in brief
|
|
|
|
|
|
MainWindow w = new MainWindow();
System.Windows.DependencyObject x = System.Windows.LogicalTreeHelper.FindLogicalNode(w, "btn");
is this the correct way ? how can i change the properties of button after accessing ?
santhapur
|
|
|
|
|
I have a Windows Form app communicating with a remote web service. Up until now, the app was a .Net 2.0 app using Web Services. Today, I converted the app to 3.5 so I could use WCF. I created a "Service Reference", and it created a bunch of files, and subsequently added stuff to the projects app.config file. I would rather have the stuff in code rather than the app.config file. Where can I get guidance on moving it to where I want it?
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
All of the elements in the config file can be moved into code. This[^] book makes a good stab at showing what goes where.
|
|
|
|
|
I have that book (and this is my first foray into the wonderfully stupid world of WPF), but...
One of the generated files is called Reference.cs - it's got 10,000 lines of code in it - geeze! All of the classes are partial. What am I supposed to do with them?
So little documentation - and even less time... :/
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
John Simmons / outlaw programmer wrote: So little documentation - and even less time...
But so much autogenerated code. If you have an area that you need moving over, let me know and I'll do my best to help.
|
|
|
|
|
Hi All,
When I first started out on WPF I found a tool called Snoop ... I couldn't ever get it to work reliably.
Well ... its had a complete overhaul ... !
Works like a charm and now has an MSI installer too!
http://blois.us/Snoop/[^]
|
|
|
|
|
|
No bother! Seems to be another of those 'god app' types a lá Reflector/Mole ...
|
|
|
|
|
Wow. That looks cool. Nice find, Jammer
"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
|
|
|
|
|
No problem Paul. I was so frustrated with the old version since I could see how useful it would be if it worked properly.
This app is really great.
|
|
|
|
|
This is just a quick question to point me in the right direction.
I want to write some sort of custom control (so far a UserControl) that will basically be defined as a TextBlock, and certain parts of that text block need to be customized by properties by the user of the usercontrol.
So I get that I can define entire properties, but how do I provide part of a property for something like a TextBlock?
For example, suppose I want a user control that creates a TextBlock with the contents "Hello {name}, how are you today?", where {name} is specified as a property of the user control.
I'm thinking something like ASPX would be nice here, how you can render an output... I don't suppose WPF has anything like that... where I can just "render" the XAML for a custom control?
The journey to WPF enlightenment continues...
Logan
“Time and space can be a bitch.”
–Gushie, Quantum Leap
{o,o}.oO( Looking for a great RSS reader? Try FeedBeast! )
|)””’) Built with home-grown CodeProject components!
-”-”-
|
|
|
|
|
Anything you can do in XAML, you can do in code - that's ultimately what XAML boils down to. So it's fairly trivial to implement something like this in code. e.g.
TextBlock textBlock1 = new TextBlock();
textBlock1.TextWrapping = TextWrapping.Wrap;
textBlock2.Background = Brushes.AntiqueWhite;
textBlock1.Inlines.Add(new Run("Hello "));
textBlock1.Inlines.Add(new Bold(new Run(userName)));
textBlock1.Inlines.Add(new Run(", how are you today?"));
Alternatively, you can add your items via XAML directly just by using three TextBlocks. Two of these blocks would be static, the third would bind to the user name.
|
|
|
|
|
Super! That's what I was looking for. Is it possible to declare something like a Run or a Span inside a string, as an inline like Bold, but set its content via binding? Or would I have to do the three separate TextBlocks as you say?
Something like this would be handy:
<textblock>Hello <run source="{Binding ...}">, how are you?
Cheers
“Time and space can be a bitch.”
–Gushie, Quantum Leap
{o,o}.oO( Looking for a great RSS reader? Try FeedBeast! )
|)””’) Built with home-grown CodeProject components!
-”-”-
|
|
|
|
|
Well, if you want to use binding, you can do this:
<StackPanel Orientation="Horizontal">
<TextBlock Text="Hello "/>
<TextBlock Text="{Binding Mode=OneWay, Path=Name}" />
<TextBlock Text=", how are you?" />
</StackPanel>
|
|
|
|
|
I managed to get something like what I wanted, by overriding the user control's OnRender method:
<UserControl ...>
<TextBlock>
Hello <Run x:Name="name" />, how are you?
</TextBlock>
</UserControl>
protected override void OnRender( DrawingContext drawingContext ) {
base.OnRender( drawingContext );
name.Text = Name;
}
Cool.
P.S.
What's that tool everyone uses to copy and paste code into html that fixes angle brackets and all that? I'm getting tired of disabling html in my messages.
|
|
|
|
|
Another really powerful feature of WPF is the ability to use converters. This could be done as:
<local:GreetingConverter x:Key="GreetingFormatter"> This is the actual text.
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Mode=OneWay, Path=Name}"
Converter={StaticResource GreetingFormatter} />
</StackPanel> This would be the class that implements the converter:
using System;
using System.Windows.Data;
namespace MySample.GreetingConverter
{
[ValueConversion(typeof(object),typeof(string))]
public class FormattingConverter: IValueConverter
{
public object Convert(object value, Type targetType,
object parameter, System.Globalization.CultureInfo culture)
{
return string.Format("Hello {0}, how are you?", value);
}
public object ConvertBack(object value, Type targetType,
object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
}
|
|
|
|
|
Fascinating. Are converters able to return WPF types, or just primitives? And are they called every time the interface is rendered, or only when things change?
“Time and space can be a bitch.”
–Gushie, Quantum Leap
{o,o}.oO( Looking for a great RSS reader? Try FeedBeast! )
|)””’) Built with home-grown CodeProject components!
-”-”-
|
|
|
|
|
They can convert between any types you want and they're called when the value changes. In 3.5 there is a StringFormat property on the binding itself. You may also want to lookup multi-bindings and multi-input converters.
|
|
|
|
|
Cool, thanks for the tips. I thought you were Pete there for a second, since he's been replying to practically all my questions, so I wanted to thank him; but thank you also.
Logan
“Time and space can be a bitch.”
–Gushie, Quantum Leap
{o,o}.oO( Looking for a great RSS reader? Try FeedBeast! )
|)””’) Built with home-grown CodeProject components!
-”-”-
|
|
|
|
|
No problems mate. I'd disappeared from the boards by the time you asked the followup. Only to glad to help mate.
|
|
|
|
|
I am trying to create labels and textboxes dynamically on a stack panel and I can't display them at run time. The reason I am creating them at run time is I have report names and report parameters stored in a table. When I select a report from a treeview I would like to create the corresponding texboxes and labels based on the data I get from the database. Below is the code for creating Report Parameter fields. In Win forms, I could use
pnlParameter.Control.Add(lbl).
private void CreateRptParmsFields(int ReportNameID)
{
_currCtrl = _staticCtrlCount + 1;
BUI.ReportParameterCollection rpc = BUI.ReportParameterCollection.FetchListByReportNameID(ReportNameID);
foreach (BUI.ReportParameter rp in rpc)
{
Label lbl = CreateLabelControl(rp);
lbl.Tag = rp;
Control ctrl;
switch (rp.Control.ToLower())
{
case "cmb":
ctrl = CreateLabelControl(rp);
break;
default:
ctrl = CreateTextBoxControl(rp);
break;
}
}
}
The two methds below are for creating labels and textboxes respectively.
private TextBox CreateTextBoxControl(BUI.ReportParameter rp)
{
TextBox t = new TextBox();
t.Name = "txt" + rp.Code.Replace("@", "");
return t;
}
private Label CreateLabelControl(BUI.ReportParameter rp)
{
Label lbl = new Label();
lbl.Name = "lbl" + rp.Code.Replace("@", "");
lbl.Width = 150;
lbl.Content = rp.Description;
return lbl;
}
Can anyone show me how to display those fields on a stack panel.
Thanks
|
|
|
|
|
<Window x:Class="HDI_WPF_ListItemTemplate_cs.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" Loaded="Window_Loaded">
<Grid>
<ListBox x:Name="lstItems" Width="300" MaxHeight="300" FontSize="16">
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Blue" Margin="0,4,0,4" BorderThickness="1" CornerRadius="5">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal" Background="AntiqueWhite">
<TextBlock FontSize="16" Text="{Binding Path=FirstName}" />
<TextBlock FontSize="16" Text=" " />
<TextBlock FontSize="16" Text="{Binding Path=LastName}" />
</StackPanel>
<TextBlock FontSize="12" Text="{Binding Path=Age}" />
<TextBlock FontSize="12" Text="{Binding Path=FavoriteMovie}" />
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</Grid>
</Window>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
lstItems.Items.Add(new MyPeopleData { FirstName = "Han", LastName = "Solo", Age = 45, FavoriteMovie = "Star Wars" });
lstItems.Items.Add(new MyPeopleData { FirstName = "James", LastName = "Kirk", Age = 36, FavoriteMovie = "Star Trek" });
lstItems.Items.Add(new MyPeopleData { FirstName = "Martha", LastName = "Jones", Age = 24, FavoriteMovie = "Dr. Who" });
lstItems.Items.Add(new MyPeopleData { FirstName = "Will", LastName = "Smith", Age = 32, FavoriteMovie = "Independance Day" });
lstItems.Items.Add(new MyPeopleData { FirstName = "Christian", LastName = "Bale", Age = 40, FavoriteMovie = "The Dark Knight" });
lstItems.Items.Add(new MyPeopleData { FirstName = "Hugh", LastName = "Jackman", Age = 46, FavoriteMovie = "Wolverine" });
}
}
public class MyPeopleData
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
public string FavoriteMovie { get; set; }
}
I want to enable context menu for the LSITBOXITEM. CAn any one help me how can i do this...
Santhapur
|
|
|
|
|
Santhapur, try this:
<Window x:Class="HDI_WPF_ListItemTemplate_cs.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" Loaded="Window_Loaded">
<Window.Resources>
<ContextMenu x:Key="myMenu">
<MenuItem Header="my text" />
</ContextMenu>
</Window.Resources>
<Grid>
<ListBox x:Name="lstItems" Width="300" MaxHeight="300" FontSize="16">
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Blue" Margin="0,4,0,4" BorderThickness="1" CornerRadius="5">
<StackPanel Orientation="Vertical" ContextMenu="{StaticResource myMenu}">
<StackPanel Orientation="Horizontal" Background="AntiqueWhite">
<TextBlock FontSize="16" Text="{Binding Path=FirstName}" />
<TextBlock FontSize="16" Text=" " />
<TextBlock FontSize="16" Text="{Binding Path=LastName}" />
</StackPanel>
<TextBlock FontSize="12" Text="{Binding Path=Age}" />
<TextBlock FontSize="12" Text="{Binding Path=FavoriteMovie}" />
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</Grid>
</Window> Here I've added the context menu as a resource, and referred to it from the StackPanel. By doing this, the context menu will only appear when you click on the item itself rather than space at the side.
|
|
|
|