|
Then you'll have to create a class that matches these columns and return a list of that class instead. You'll use the select projection to fill that class.
"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 a lot, if possible can u plz give me an example on how to achieve it.
|
|
|
|
|
Bear in mind that I'm a C# developer (not a VB.NET one), so I may not get the syntax 100% correct, but I should imagine that this will work:
Public Function GetLoginName(ByVal strLogin As String) As List(Of UserSubset)
Implements IService1.GetLoginName
Dim db As New DataClasses1DataContext
Dim matchingLogin = From Login In db.tbl_Users Where Login.UserName.StartsWith(strLogin) _
Select New UserSubset With {.Name = Login.UserName, .Password = Login.Password }
Return matchingLogin.ToList
End Function You will need to create a class called UserSubset that contains the properties Name and Password . That should be good enough to get you started.
"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, i will try this out.
|
|
|
|
|
Hi, I am using Visual Studio 2008 for building WPF 3.5 SP1 application.
I came up with a problem which I need to develop. Hope you guys can help me...
I need to create an application which will load images dynamically & position them in the screen randomly. I need to show maximum 10 images & they should not overlap each other.
Here is the sample view:
Problem Statement (ScreenShot)[^]
There will be a central image at position 'B' and the rest of the images will be in various locations 'X' connected with 'B'.
How can I implement the logic? As the images will be dynamic & can vary from 2-10 images. Please guide me with proper solution.
Regards,
- Kunal Chowdhury ( My Blog)
|
|
|
|
|
You generate random numbers and then reject them if they overlap with any existing image.
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.
|
|
|
|
|
Hi friend
i want to create custom Expander control. in my expander control there will be three or four more button they will have to register there cick event where ever my custom control is used.
Now i create new custom control inherit it from Expander and Now how i can add my desired buttons and there Click event plz help me?????
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
|
|
|
|
|
Why not restyling the Expander control?
A good starting point is simply to take the default style / template and modify it.
I don't know if there is a well known place to find the Aero template, so I just use Reflector to uncompile the XAML resource file for the WPF UI Control.
For your convenience here is the default aero style of the expander:
<Style x:Key="{x:Type Expander}" TargetType="{x:Type Expander}">
<Setter Property="Foreground" Value="{DynamicResource {x:Static ControlTextBrush}}" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Expander}">
<ControlTemplate.Triggers>
<Trigger Property="IsExpanded" Value="true">
<Setter TargetName="ExpandSite" Property="Visibility" Value="Visible" />
</Trigger>
<Trigger Property="ExpandDirection" Value="Right">
<Setter TargetName="ExpandSite" Property="Dock" Value="Right" />
<Setter TargetName="HeaderSite" Property="Dock" Value="Left" />
<Setter Value="{StaticResource Ó}" TargetName="HeaderSite" Property="Style" />
</Trigger>
<Trigger Property="ExpandDirection" Value="Up">
<Setter TargetName="ExpandSite" Property="Dock" Value="Top" />
<Setter TargetName="HeaderSite" Property="Dock" Value="Bottom" />
<Setter Value="{StaticResource Ô}" TargetName="HeaderSite" Property="Style" />
</Trigger>
<Trigger Property="ExpandDirection" Value="Left">
<Setter TargetName="ExpandSite" Property="Dock" Value="Left" />
<Setter TargetName="HeaderSite" Property="Dock" Value="Right" />
<Setter Value="{StaticResource Ô}" TargetName="HeaderSite" Property="Style" />
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Value="{DynamicResource {x:Static GrayTextBrush}}" Property="Foreground" />
</Trigger>
</ControlTemplate.Triggers>
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="3" SnapsToDevicePixels="true">
<DockPanel>
<ToggleButton Name="HeaderSite" Dock="Top" Margin="1" MinWidth="0" MinHeight="0" Style="{StaticResource Ñ}" FocusVisualStyle="{StaticResource Ò}" Content="{TemplateBinding Header}" ContentTemplate="{TemplateBinding HeaderTemplate}" ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}" Foreground="{TemplateBinding Foreground}" Padding="{TemplateBinding Padding}" FontFamily="{TemplateBinding FontFamily}" FontSize="{TemplateBinding FontSize}" FontStyle="{TemplateBinding FontStyle}" FontStretch="{TemplateBinding FontStretch}" FontWeight="{TemplateBinding FontWeight}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" IsChecked="{Binding Path=IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" />
<ContentPresenter Name="ExpandSite" Dock="Bottom" Visibility="Collapsed" Focusable="false" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="{TemplateBinding Padding}" />
</DockPanel>
</Border>
</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 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
|
|
|
|
|