|
Like in .NET FW 2.0, there is Anchor property to set the controls Auto arrange. It will be much helpful if anyone could share info about similar property in WPF
|
|
|
|
|
For objects that are placed inside a grid a combination of HorizontalAlignment, VerticalAlignment and Margin can be used to control the position in a similar way to "Anhor".
Anchor right & bottom <=> HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="<not used="">,<not used="">,<distance from="" right="" edge="">,<distance from="" bottom="" edge="">"
Anchor left & right <=> HorizontalAlignment="Stretch".
As I said the controls must be placed inside a grid;
Mihai,
|
|
|
|
|
|
Don't think in terms of anchors ... WPF is a different beast.
As well as using Layout Grids you need to think about putting stack panels and so forth inside grids in order to get the layout of things working properly.
Simply using grids and then margins and so on will yield a UI that doesn't always scale well. Grids are good for deviding up UI but not the best way to actually position things ...
|
|
|
|
|
Ok,
I've defined a simple class called NonDataNode that has two members, Name (string) and ContainedItems (object) which will hold whatever type of object is contained by that node in the tree (couldn't be more specific because it could be just about anything). I also created another class called NonDataNodeList, which inherits from List<NonDataNode>. There are no changes in implementation, I just wanted a name that was easier to work with in XAML. ImageOutputType is a business object in my application. lib and local are namespaces defined with xmlns elements at the top of the XAML. The Window.Resources section is before the tree control.
So, the XAML for my treeview looks like this:
<TreeView Grid.Column="0" Grid.Row="2" HorizontalAlignment="Stretch" Background="Transparent" Foreground="{StaticResource TreeViewItemText}"
BorderBrush="DarkRed" BorderThickness="1" x:Name="trvNavigate" ItemTemplate="{StaticResource NonDataNodeTemplate}" >
</TreeView>
In my Window.Resources section, I've defined the following:
<HierarchicalDataTemplate DataType="local:NonDataNode" ItemsSource="{Binding Path=ContainedItems}" x:Key="NonDataNodeTemplate">
<TextBlock Text="{Binding Name}" Style="{StaticResource TreeViewNodeText}"/>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="lib:ImageOutputType">
<TextBlock Text="{Binding Name}" Style="{StaticResource TreeViewNodeText}"/>
</HierarchicalDataTemplate>
You can see that the key for the heirarchical data template is NonDataNodeTemplate and that the treeview uses that as the item template. However, when I try to run this thing, I get the following error:
Cannot find resource named '{NonDataNodeTemplate}'. Resource names are case sensitive. Error at object 'trvNavigate' in markup file 'WGAdminPanel;component/mainwindow.xaml' Line 76 Position 82.
Now, I'm sure it's something simple I'm missing, but I've been stuck on this for about 4 hours. Can someone help me? I've tried google, but so far I haven't found any examples that I can make work.
Thanks,
Will
|
|
|
|
|
what happens if you try this:
DataType="{x:Type local:NonDataNode}" instead of DataType="local:NonDataNode" ?
Mihai,
|
|
|
|
|
That fixed it. Thank you.
|
|
|
|
|
Hi Guys,
I have created two xaml files , 1. Page1.xaml and 2. Page2.xaml
Page1.xaml has a Hyperlink with click event associated with a method as below:
<Grid>
<TextBlock>This is a <Hyperlink Name="myLink" Click="hyperlink_Clicked">hyperlink</Hyperlink> to page 2</TextBlock>
</Grid>
In page1.xaml.cs, i have created the method hyperlink_Clicked as below:
private void hyperlink_Clicked(object sender,System.EventArgs erg)
{
System.Uri myUri = new Uri("Page2.xaml",System.UriKind.Relative );
myLink.NavigateUri = myUri;
}
However, when i click on hyperlink for the first time, it does not navigate to page2, but if i click second time it goes to page2. Am i missing anything? late Binding or early binding?
Any help , appreciated.
Thanks
happy coding!
|
|
|
|
|
Without having tryed to reproduce your issue I suspect that the link would only work if it is in a focused control and that it is not the case when you first click.
Setting the focus reliably can only be done in the Loaded event, as it is well undocumented! , I suggest you write something as follow:
MyControl()
{
Loaded += (sender, e) => { Focus(); };
}
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.
|
|
|
|
|
I have two sahpes created using Path which has Data Property. One Path is smaller and the other is Larger. I want to animate smaller Path and make it look like larger path. Please suggest me how to do this.
Path 1 :
path strokethickness="2.000000" stroke="#000000" fill="#000000" data="F1 M 148.692383,566.845703 L 198.179199,566.845703 L 197.963867,545.753906 L 197.757324,525.583984 L 138.201660,525.583984 C 138.201660,525.583984 139.660156,534.376953 141.660156,541.126953 C 143.660156,547.876953 148.692383,566.845703 148.692383,566.845703 Z" width="87.077" stretch="Fill"
Path 2 :
path strokethickness="2.000000" stroke="#000000" fill="#000000" data="F1 M 200.701172,444.335938 C 200.701172,444.335938 201.902344,454.123047 201.902344,467.187500 C 201.902344,477.767578 201.246582,481.021484 199.109375,489.334961 L 129.755859,489.334961 C 124.140625,485.524414 120.946777,474.328125 120.035156,463.418945 C 119.187988,453.281250 124.750488,444.418945 124.750488,444.418945 L 200.701172,444.335938 Z" stretch="Fill"
Thanks In advance.
|
|
|
|
|
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="DemoAnim.Window1"
x:Name="Window"
Title="Window1"
Width="640" Height="480">
<Window.Resources>
<Storyboard x:Key="GrowEllipse">
<doubleanimationusingkeyframes begintime="00:00:00" storyboard.targetname="ellipse" storyboard.targetproperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" mode="hold" /> <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="1.643"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="ellipse" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="1.643"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="ellipse" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="ellipse" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Window.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource GrowEllipse}"/>
</EventTrigger>
</Window.Triggers>
<Grid x:Name="LayoutRoot">
<Ellipse Fill="#FFFF0000" Stroke="#FF000000" Margin="176,127,0,214" StrokeThickness="5" Width="112" HorizontalAlignment="Left" x:Name="ellipse" RenderTransformOrigin="0.5,0.5">
<Ellipse.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1"/>
<SkewTransform AngleX="0" AngleY="0"/>
<RotateTransform Angle="0"/>
<TranslateTransform X="0" Y="0"/>
</TransformGroup>
</Ellipse.RenderTransform>
</Ellipse>
<Ellipse Fill="#FFFF0000" Stroke="#FF000000" StrokeThickness="5" Margin="0,91,75,178" Width="184" HorizontalAlignment="Right"/>
</Grid>
</Window>
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
I would be very grateful to anyone who would explain me what's wrong with my code.
In the code below I'm creating TextBoxes dynamically when user clicks on the TextBlock. I want each new TextBox be focused (i.e. the blinking cursor to be in the TextBox), but it works only for the first one. 2-nd, 3-rd and following TextBoxes became focused only when I switch to another tab in Firefox and than switch back again. How can I make the last created TextBoxes focused?
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace TextBoxCase
{
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
TextBlock txtBlock = new TextBlock();
txtBlock.Text = "Create new TexBox!";
txtBlock.MouseLeftButtonDown += txtBlockClick;
panel.Children.Add(txtBlock);
}
void txtBlockClick(object sender, MouseButtonEventArgs e)
{
TextBox txtBox = new TextBox();
txtBox.Loaded += new RoutedEventHandler(txtBox_Loaded);
panel.Children.Add(txtBox);
}
void txtBox_Loaded(object sender, RoutedEventArgs e)
{
((TextBox)sender).Focus();
}
}
}
In the xaml code I only have StackPanel named "panel".
|
|
|
|
|
Alex Skye wrote: ((TextBox)sender).Focus();
Maybe you can switch '((TextBox)sender).Focus();' with '((TextBox)sender).Activate();'
If this doesn't work will you post the way you fixed it?
Thanks
|
|
|
|
|
Can anybody share some piece of code about how to maintain session for every user logging in through WPF browser application.
|
|
|
|
|
|
Mis$Fit wrote: have been created a wpf listview consisiting gridview now i want to change the color where my gridview column has "Failed" value....how i can do this
Use a DataTrigger.
|
|
|
|
|
plz anyone can give me a sample code oor a link that can help me...
|
|
|
|
|
Google has lots, but perhaps this[^] one from our very own RockStar might help.
|
|
|
|
|
Why do folks delete OP ???
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Jammer wrote: Why do folks delete OP ???
Because they're stupid.
|
|
|
|
|
HAHA!
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Hi,
can u help me know how to proceed with maintaining session state in wpf browser application.
|
|
|
|
|
Hi Puneet,
XBAP is a client side technology, and it cannot use session directly. XBAP is similar to WPF Windows application the main difference is that XBAP application runs on the browser. As you cannot use session in a standalone Windows application similarly session cannot be used in a XBAP application. However, if your web site is developed by ASP.NET, you can disable session cookies. Instead, the session id will be passed by a request parameter in the URL. Now you can use this parameter in your XBAP.
Hope this information will be helpful .
Regards,
John Adams
ComponentOne LLC
|
|
|
|
|
Hi...i'm new to wpf.
I have a problem and i dont find a solution on web.
I have an usercontrol (name PresenterControl.xaml) used as a container for other usercontrols (WindowContainerControl.xaml in this case). From code i think you'll understand what i;m trying to do.
The content of PresenterControl it;s a label. this content will be forwarded inside PresenterContent to WindowContainerControl. WindowContainerControl will put it inside a grid.
i;m getting this error and i have no solution in mind.
Key cannot be null.
Parameter name: key
at System.Collections.Specialized.ListDictionary.get_Item(Object key)
at System.Collections.Specialized.HybridDictionary.get_Item(Object key)
at System.Windows.StyleHelper.QueryChildIndexFromChildName(String childName, HybridDictionary childIndexFromChildName)
please help me if this issue can be solved and if i;m not asking too much please modify my example if you find a solution. thanks a lot.
Window1.xaml
<window x:class="WpfApplication3.Window1" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:myControls="clr-namespace:WpfApplication3"
Title="Window1" Height="300" Width="300">
<grid>
<mycontrols:presentercontrol xmlns:mycontrols="#unknown">
<label>Label text</label>
</mycontrols:presentercontrol>
</grid>
</window>
PresenterControl.xaml
<usercontrol x:class="WpfApplication3.PresenterControl" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:myControls="clr-namespace:WpfApplication3"
Height="300" Width="300">
<usercontrol.contenttemplate>
<datatemplate>
<grid>
<border background="Black" height="30" verticalalignment="Top" />
<mycontrols:windowcontainercontrol xmlns:mycontrols="#unknown">
<contentpresenter margin="3" content="{TemplateBinding Property=Content}" />
</mycontrols:windowcontainercontrol>
</grid>
</datatemplate>
</usercontrol.contenttemplate>
</usercontrol>
WindowContainerControl.xaml
<usercontrol x:class="WpfApplication3.WindowContainerControl" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<usercontrol.contenttemplate>
<datatemplate>
<grid>
<grid.rowdefinitions>
<rowdefinition height="20" />
<rowdefinition height="*" />
</grid.rowdefinitions>
<!-- Butoanele ferestrei -->
<border background="Red" grid.row="0" cornerradius="5,5,0,0">
<grid>
</grid>
</border>
<border background="Blue" grid.row="1" cornerradius="5,5,0,0">
<grid>
<contentpresenter margin="3" content="{TemplateBinding Property=Content}" />
</grid>
</border>
</grid>
</datatemplate>
</usercontrol.contenttemplate>
</usercontrol>
|
|
|
|
|
I wouldn't expect any of that to work!! Don't do things like:
<usercontrol x:class="WpfApplication3.WindowContainerControl" xmlns:x="#unknown">
Your cutting off the other xmlns statements that follow by using a > character at the end of that line for starters. I have no idea what your trying to do with:
xmlns:x="#unknown"
Are you making this XAML by hand in VS? I suggest you go and grab a trial version of Expression Blend and have a play around with that first.
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|