|
thnx buddy.
i solve the problem by creating the custom control for the Expander. take idea from( Form link
)
i add the buttons in template here is the xaml
<Style TargetType="{x:Type local:CustomControl1}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:CustomControl1}">
<ControlTemplate.Resources>
<OuterGlowBitmapEffect x:Key="outerGlow" GlowColor="Brown" GlowSize="0"></OuterGlowBitmapEffect>
<!-- Style for the toggle button which wil be used as expander header -->
<Style TargetType="{x:Type ToggleButton}" x:Key="toggleButtonKey">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border Background="White">
<Grid Background="Aquamarine"
Margin="{TemplateBinding Padding}">
<ContentPresenter ContentSource="{TemplateBinding Content}" Margin="5"/>
<Grid Background="Transparent">
<Ellipse x:Name="shadow" Visibility="Hidden"
HorizontalAlignment="Center" VerticalAlignment="Center"
Width="17" Height="17" />
<Path x:Name="arrow"
VerticalAlignment="Center" HorizontalAlignment="Center"
Stroke="#666" StrokeThickness="2"
Data="M1,1 L4,4 7,1" />
</Grid>
</Grid>
</Border>
<ControlTemplate.Triggers>
<!-- Trigger to change the arrow direction when expanded -->
<Trigger Property="IsChecked" Value="true">
<Setter TargetName="arrow"
Property="Data" Value="M 1,4 L 4,1 L 7,4"/>
</Trigger>
<!-- Trigger to give a mouse over effect on the circle containing direction arrow -->
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="arrow"
Property="Stroke" Value="#222"/>
<Setter TargetName="shadow"
Property="Visibility" Value="Visible"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ControlTemplate.Resources>
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Grid>
<!-- Expander -->
<StackPanel>
<!-- Expander Header -->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<ToggleButton x:Name="expanderHeader" Grid.Column="0" HorizontalAlignment="Left"
Width="{TemplateBinding Width}"
Style="{StaticResource toggleButtonKey}"
Content="{TemplateBinding Header}"
Padding="{TemplateBinding Padding}"
IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsExpanded,Mode=TwoWay}"/>
<StackPanel Orientation="Horizontal" Grid.Column="1">
<Button x:Name="btnHistory" Content="History"/>
<Button x:Name="btnNotes" Content="Notes"/>
<Button x:Name="btnMedication" Content="Medication"/>
</StackPanel>
</Grid>
<!-- Expander Content -->
<ContentPresenter x:Name="expanderContent"/>
</StackPanel>
</Grid>
</Border>
<ControlTemplate.Triggers>
<!-- Trigger for showing the popup when Expander control is not expanded and IsMouseOver is true -->
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition SourceName="expanderHeader" Property="IsMouseOver" Value="True"></Condition>
<Condition SourceName="expanderHeader" Property="IsChecked" Value="False"></Condition>
</MultiTrigger.Conditions>
</MultiTrigger>
<!-- Trigger for setting the content of expander when IsExpanded is true -->
<Trigger SourceName="expanderHeader" Property="IsChecked" Value="True">
<Setter TargetName="expanderContent"
Property="Visibility" Value="Visible"></Setter>
</Trigger>
<Trigger SourceName="expanderHeader" Property="IsChecked" Value="False">
<Setter TargetName="expanderContent"
Property="Visibility" Value="Collapsed"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
and in CustomControl.cs i added
public CustomControl1()
{
this.Loaded += new RoutedEventHandler(CustomControl1_Loaded);
}
void CustomControl1_Loaded(object sender, RoutedEventArgs e)
{
Button btn = Template.FindName("btnHistory", this) as Button;
if (btn != null)
{
btn.Click += new RoutedEventHandler(btn_Click);
}
Button btnNotes = Template.FindName("btnNotes", this) as Button;
if (btnNotes != null)
{
btnNotes.Click += new RoutedEventHandler(btnNotes_Click);
}
Button btnMedcation = Template.FindName("btnMedication", this) as Button;
if (btnMedcation != null)
{
btnMedcation.Click += new RoutedEventHandler(btnMedcation_Click);
}
}
is this is right approach or not.
plz reply
WANTED wasim khan(Killed 50 Innocent Buggs, Distroyed 200 Exception, make 5 Project Hostage) any Compnay Hire him will pay 30,000. Best place where u can get him is Sorcim Technologies Murre Road RWP
|
|
|
|
|
This will probably work (I didn't scrutinize the code much).
However, to create really reusable control, adding an event handler on a button define in a template in the IsLoaded event is not the best approach.
1. slightly better is to add the event listener in OnApplyTemplate
2. much better is to have those button trigger a (public static) command (defined in the class).
And in the code, do not register event handler, instead add some command binding to handle the event.
For exemple, here is a snippet of my file picker control (note that I used a predefined ApplicationCommands.Open, but this can easily be replace by "public readonly static MyCommand = new RoutedCommand()")
-- (snippet) FilePicker.cs --
public class FilePicker : Control
{
public FilePicker()
{
CommandBindings.Add(new CommandBinding(
ApplicationCommands.Open,
OnOpenCommand
));
}
private void OnOpenCommand(object sender, ExecutedRoutedEventArgs e)
{
}
-- (snippet) FilePicker.generic.xaml --
<Style TargetType="{x:Type local:FilePicker}" x:Key="{x:Type local:FilePicker}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:FilePicker}">
<DockPanel>
<Button DockPanel.Dock="Right" Content="..." MinWidth="20" Command="{x:Static ApplicationCommands.Open}"/>
<TextBox IsReadOnly="True" Text="{TemplateBinding FileName}" />
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
thnx man u really give me direction and i think u solution will work for me to
WANTED wasim khan(Killed 50 Innocent Buggs, Distroyed 200 Exception, make 5 Project Hostage) any Compnay Hire him will pay 30,000. Best place where u can get him is Sorcim Technologies Murre Road RWP
|
|
|
|
|
Ok, quick background (actual question in bold below):
I built my own set of classes to define in XAML, sort of like a template to be used in multiple formats. In this case, representing a spreadsheet either on the screen or as an export to Excel. Looks like this:
<vm:SpreadsheetView> <-- GUI component inheriting from WPF Grid panel
<vm:SpreadsheetView.Model> <--- Property
<Spreadsheet> <-- Non-GUI objects, that get translated
<Spreadsheet.Styles>
<NamedStyle Key="x">FS=B</NamedStyle>
</Spreadsheet.Styles>
<RegionElement>
<Cell>Testing</Cell>
<Cell ColSpan="2">Next Cell</Cell>
<Cell Row="1" Col="2" Style="@x">Over Here</Cell>
<Cell Row="2" Col="1">Down here too</Cell>
</RegionElement>
</Spreadsheet>
</vm:SpreadsheetView.Model>
</vm:SpreadsheetView>
Basically, the SpreadsheetView reads in a tree of my homemade classes, sets up column definitions, and builds a spreadsheet-like view for it. It just walks down through the child tree whenever the Model property is set. Simple enough.
Now, all of my model classes use a simple parent/child setup, where everything has a parent object except the top-level one. RegionElements have a "Children" property, which is an inherited ObservableCollection that sets the parent of a child element when it's added (Overrides the Set/Insert/Remove/Clear). This works just fine.
The trick is the order in which things happen... What I need is for the properties (Specifically the Style property) to not be assigned until AFTER the element is added to the parent, since the styles walk up the tree to find values.
I've tried the DependsOn attribute: [System.Windows.Markup.DependsOn("Parent")]
But that doesn't work, since the Parent property is set through code. Is there any way I can tell the XAML parser to not set that property until afterward?
|
|
|
|
|
Nope....
But maybe you can have all the binding made to look for change in your properties?
If you use DependencyProperty or implement INotifyPropertyChanged, you could get rid of all order of loading / DataTemplating and DataBinding issues...
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Was trying to avoid using DependencyProperties for everything. The model itself is going to have hundreds of fields (Some of my custom classes generate groups of others - Think reporting tool), so I was leaning toward a create-and-forget layout.
I did some more research, and it seems WPF actually DOES do a top-down loading order, but only for classes derived from FrameworkElement (There's an attribute that only affects those).
I used a different strategy, first letting it be created bottom-up style, then manually traversing it top-down to apply the properties. It's not as clean, but it works.
|
|
|
|
|
I also mentioned INotifyPropertyChanged, did you notice?
All my model class are plain CLR object now.
But I do implement INotifyPropertyChanged, and it works like a charm, and tracks my change!
No need for DependencyProperty.
Better your UI update as does your model with that!
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
That would work, but it's geared more for a one-time load than real-time updates.
Here's a better example of how it works:
<RegionElement Style="B=LR">
<Cell>Some Text</Cell>
<Cell Style="B=TB">Middle cell</Cell>
<Cell>Other text</Cell>
</RegionElement>
I have my own codes set up for styles, so I can define them easily as strings, but as a quick summary, "B" stands for border, and it takes L,T,R,B for the sides (Among other things)...
So the idea here is that the RegionElement gets defined, and gets a style set, so it knows that it and everything inside it will by default have borders on the left and right sides.
Then the middle cell gets defined, and has a style for borders on the top and bottom. Now, it can look up to its parent element (Only one level up in this case) and see that it should start with left and right... It combines the two, and puts a border on all four sides.
What REALLY happens is that the middle cell gets a style of "TB" (Top/bottom), but doesn't have a parent yet, because WPF set the properties before adding it to the RegionElement. It has no parent, so just uses left/right, and never sees top/bottom.
My solution was to give the base class for GridElements an Initialize() method, so the style is first just stored as a string, and then when the model is put together, an Initialize() call runs down the tree and does the processing on that style.
It's not ideal, but going the INotifyPropertyChanged route adds more overhead than is warranted, as this was never intended to be updated in real-time.
(This framework is starting to come together really nicely... Wish I could release it on CP, but it's work-for-hire, so not mine to give away)
|
|
|
|
|
Hi, I am using WPF 3.5 SP1 to build Desktop based application.
I want to make my application such that, it can check for the online status. If internet connection is available, it will call the WCF service & cache the data locally. If internet connection is not available, it will peek up the data from the local cache. If my application closed & then restarted after 5 days it should remain the cache & display data from that. Only if internet connection is available it will fetch the new data.
Is it possible in WPF? If so, how can I achieve this? Please share the link/code for achieving this...
Regards,
- Kunal Chowdhury ( My Blog)
|
|
|
|
|
If I were you I'd look into using Microsoft's Sync Framework[^], which was designed to cope with tasks like this. Here's a sample using it[^].
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Thanks Pete O'Hanlon. Exactly the same thing I was looking around...
Regards,
- Kunal Chowdhury ( My Blog)
|
|
|
|
|
Hi!
i have created tree view demo in WPF by Using sir Josh Smith sample code but i want to give header and when header is clicked it sort data. i want to create demo like this
header1………….header2……….header3
-parent1…………..parent2………..parent3
…-child1……………-child1………….child1
……child1……………-child1…………child1
-parent2…………..parent2………..parent2
…-child2……………-child2………….child2
……child……………-child2…………child2
parent3…………….parent3………..parent3
plz suggest any link or samples code.
thank you!
|
|
|
|
|
Hi,
I am working on WPF controls, I have a halt at adjusting one of the controls programatically.
I have 2 radiobuttons (rdbtn1, rdbtn2) and a dockpanel(2 controls) with a stackpanel(with textbox and button)a another stackpanel(with 2 textboxes).
so the panels are placed at (40,10,0,0) and (40,150,0,0) with panel1 above and panel2 below it.
actually the problem is selecting one of radiobuttons .
if i select rdbtn2, the panel1 shuld be invisible and the panel2 should stretch (not shift, which mean if the panel2 height is 200 and it should stretch its starting point in vertical to 10 and its lower limit should be same , making total height of 140 + 200 )to the panel1 starting location .
so, only panel2 shuld be visible. how to do this programatically in C#?
Please help..
Thank you,
Ramm
|
|
|
|
|
I would put them in a stackpanel or a grid, and try to set them up so their size is determined by the available space, so that when you collapse one, the other would fill the space.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Okay, I found out what's eating my (non-keyed) global style. I had this in my app.xaml (my global textbox style is in Styles.xaml):
<ResourceDictionary Source="/PresentationFramework.Aero;V3.0.0.0;31bf3856ad364e35;component/themes/aero.normalcolor.xaml" >
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/WpfTest;component/Dictionaries/Resources.xaml" />
<ResourceDictionary Source="/WpfTest;component/Dictionaries/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
When I changed it to this, all of a sudden my style started to work as expected:
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/WpfTest;component/Dictionaries/Resources.xaml" />
<ResourceDictionary Source="/WpfTest;component/Dictionaries/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
0) Why does this work like this? Is it a bug or "as designed"?
1) The reason I was adding the aero.normalcolor resource dictionary was to force XP to use the aero theme. How do I force the aero look and still be able to use my own global style overrides? Can I do this and get the same results?
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/PresentationFramework.Aero;V3.0.0.0;31bf3856ad364e35;component/themes/aero.normalcolor.xaml" />
<ResourceDictionary Source="/WpfTest;component/Dictionaries/Resources.xaml" />
<ResourceDictionary Source="/WpfTest;component/Dictionaries/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
"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
|
|
|
|
|
Sadly, I found out that SL 3 doesn't support the FlowDocument.
I need to load a xaml file from the server into the client browser. No problem doing that using the webservice. The problem is how to display the file in a page and allow for printing.
NOTE: The xaml file is actually a simple table having 2 columns and several rows with simple text attributes
|
|
|
|
|
You can use
XamlReader.Load() .
Hope it helps.
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
Microsoft MVP (Silverlight), WPF/Silverlight Insiders
|
|
|
|
|
We have a number of button images used in our app. As expected, management isn't sure that it's happy with the current images, so I am trying to come up with several different sets that can easily be swapped into the application. What's the best way to go about doing this? Is "use themes" the answer? If so, can someone steer me to relevant discussions/examples?
"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
|
|
|
|
|
I'm not sure how theming work, never did it myself.
Although this codeplex library can help perhaps?
http://wpfthemes.codeplex.com/[^]
In my case I use object template in the App resource if I want to change the look of the object.
But your case is a it different.
You don't specially want to change the look of button in general (or so it seems) but of individual button in particular...
Maybe their image content or whatever could be:
<Button Content="{StaticResource buttonFooContent}">
And then in you app resource you can define
<SomeUI x:Key="buttonFooContent" x:Shared="true" />
and you can change the content anytime in the App resource file and everyone will get it!
How about that?!
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
This[^] article isn't a bad start.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hey all
Im new to silverlight, just want to know how to embed or add silverlight to an existing ASP.net project. In flash you only use the following code:
<object width="871px" height="400px">
<param name="aa" value="aa.swf" />
<embed src="flash\aa.swf" width="871px" height="400px"></embed>
</object>
Can someone tell me how do it with Silverlight.
Thanx
|
|
|
|
|
|
|
Hi,
I have a few vector images in XAML format that I'd like to display in my application. So far I've been able to do this using:
private XmlReader reader_;
private UIElement control_;
...
reader_ = XmlReader.Create(filename_);
control_ = (UIElement)XamlReader.Load(reader_);
Then having a Control property:
public UIElement Control
{
get
{
return control_;
}
}
And binding to this as below:
<DataTemplate DataType="{x:Type local:Tile}">
...
<Viewbox>
<Label Content="{Binding Control}" />
</Viewbox>
...
This works, but when I try and display the control in multiple controls in the same window, only one will appear. I was able to fix it by doing this:
public UIElement Control
{
get
{
XmlReader reader = XmlReader.Create(filename_);
return (UIElement)XamlReader.Load(reader);
}
}
But I'd really like to avoid parsing the XAML and reloading the control every time I use it! This is my first WPF project. Can someone recommend a better way of doing this?
Cheers!
Jack
|
|
|
|
|
I define my vector images as resources, then create controls which point to that resource for their background property, from memory.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|