|
Hello,
Thanks for the links. However now I am stuck. This code doesn't do anything - my lines just keeps not being visible.
double left = horizontalLineContainer.Margin.Left;
double top = horizontalLineContainer.Margin.Top;
double right = horizontalLineContainer.Margin.Right;
double bottom = horizontalLineContainer.Margin.Bottom;
horizontalLineContainer.Margin = new Thickness(left, top, left, bottom);
ThicknessAnimation animation = new ThicknessAnimation();
animation.Duration = new TimeSpan(0, 0, 2);
animation.From = horizontalLineContainer.Margin;
animation.To = new Thickness(left, top, right, bottom);
Storyboard.SetTarget(animation, horizontalLineContainer);
Storyboard.SetTargetProperty(animation, new PropertyPath(Grid.MarginProperty));
Storyboard storyboard = new Storyboard();
storyboard.Children.Add(animation);
storyboard.Begin();
Thanks,
Theo
|
|
|
|
|
OK, so I got it to display. It seems it does the animation, but it's extremely fast, no matter what TimeSpan I enter, be it 2 or 20000 seconds. Here's my code:
double left = horizontalLineContainer.Margin.Left;
double top = horizontalLineContainer.Margin.Top;
double right = horizontalLineContainer.Margin.Right;
double bottom = horizontalLineContainer.Margin.Bottom;
horizontalLineContainer.Margin = new Thickness(left, top, left, bottom);
horizontalLineContainer.Visibility = Visibility.Visible;
ThicknessAnimation animation = new ThicknessAnimation();
animation.Duration = new TimeSpan(0, 0, 20000);
animation.From = horizontalLineContainer.Margin;
animation.To = new Thickness(left, top, right, bottom);
Storyboard.SetTargetName(animation, horizontalLineContainer.Name);
Storyboard.SetTargetProperty(animation, new PropertyPath(Grid.MarginProperty));
Storyboard storyboard = new Storyboard();
storyboard.Children.Add(animation);
storyboard.Begin(horizontalLineContainer);
NOTE: I would like to say that this is very urgent, as this is a school task due monday. Any help is appreciated.
Thanks,
Theo
|
|
|
|
|
I don't see how that works at all. The "From" and "To" are identical.
|
|
|
|
|
Hi Guys,
I've got a MyUserControl i have created for my app. When i click on, or mouse over the MyUserControl, i'd like the events to be raised with the MyUserControl as the OrigionalSource. As they are composite controls, made up of numerous other controls, i get whatever child control was clicked inside MyUserControl.
How do i go about achiving this?
Regards
Tristan
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
AFAIK, you can only get the control for which the event was fired.
Use the VisualTreeHelper's VisualTreeHelper.FindElementsInHostCoordinates method to get all control within the mouse position from where the event was fired.
|
|
|
|
|
You could make them all global (setting a property for the element in XAML, or when you create them in code. At that point, you can subsribe to those events anywhere you want.
I know it's cheating, but it works, and you can't afford to spend a week on this stuff. Right?
.45 ACP - because shooting twice is just silly ----- "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." - J. Jystad, 2001
|
|
|
|
|
Hi, thanks. that got me thinking, and in the end i implemented an ITarget interface on every control i wanted clicked, and looped through the parent controls until I found an implementor.
Surely there's a better way.
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
The "best" way is whatever you can get to work. Remember, your project is late (no matter if it actually is or not).
.45 ACP - because shooting twice is just silly ----- "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." - J. Jystad, 2001
|
|
|
|
|
Well, that depends on who's maintaining the "best" way :P
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
With a WinForms hyperlink you can set it to only be underliend when the mouse is over it. How can I do this in a WPF hyperlink?
Everything makes sense in someone's mind
|
|
|
|
|
Write a Style for Button like a Hyperlink and do whatever you want to do.
Advantage:
- You got a Hyperlink as you asked for
- You will get more events than a Hyperlink.
|
|
|
|
|
Could you explain how to do that? I'm rather new to WPF.
TIA
Everything makes sense in someone's mind
|
|
|
|
|
Hi
Since I am building the columns from code-behind, I need to attach hyperlink into one of the columns from code behind. And also, I need to add the click event.
How can I do that and its data-binding in code behind? Please advise.
Thanks
AJ
Follow your goals, Means will follow you ---Gandhi---
|
|
|
|
|
I just did that in our own silverlight app (I assume you're talking about a regular Grid (as opposed to a DataGrid).
I simply created the button and set the Tag property indicating it's purpose (or associated data). This kept me from having to set a unique Name . After the button was created, I subscribed to the Click event (all buttons used the same event method), and then added the button to the appropriate grid column/row.
In the event handler, the Tag object indicated what the button was supposed to do.
.45 ACP - because shooting twice is just silly ----- "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." - J. Jystad, 2001
|
|
|
|
|
I have written a Silverlight 4 application that reads a data stream and interprets it to dynamically create a web page. As part of the design I need to add grids to the page to act as placeholders to mimic the appearance and behaviour of tables. Here I am dynamically creating a grid with [gridCols] number of columns:
Grid LocalGrid = new Grid();
LocalGrid.Width = Double.NaN; // Auto Width and Height
LocalGrid.Height = Double.NaN;
for (int c=1; c <= gridCols; c++) // Add the columns
{ // Add a new column to the grid
LocalGrid.ColumnDefinitions.Add(new ColumnDefinition() { MinWidth = 10.0 });
}
LocalGrid.Background = new SolidColorBrush(Colors.LightGray);
So far, so good. I can now add rows as I need them with:
LocalGrid.RowDefinitions.Add(new RowDefinition() { MinHeight = 15 });
When the grid is fully loaded and formatted I can add it to a placeholder on the web page.
So, question, how can I get at and programmatically alter the properties of the added rows? For example how can I set the background colour of a row to do an alternating-row colour scheme. I have seen examples of using the LoadingRow event, but this grid is not data-bound.
Grid rows do not have properties such as BackColor exposed. I'm guessing that I need to use SetValue but, if so, what are the required parameters and how can I see a list of the dependency properties?
Any help greatly appreciated.
Kind regards
Paul
________________
Eschew Obfuscation
Anon
|
|
|
|
|
I guess you might be adding one or more controls to every row that you create.
Setting the background color of the parent control in every alternate row may help you solve this problem.
This is definitely not an optimal way, but perhaps the only way (for a
Grid control).
Setting alternate row colors for an items control is relatively easier and uses the approach you have mentioned in your post (using LoadingRow).
|
|
|
|
|
Hi,
I have a problem with rotating a WPF UIElement and placing it within a small space.
Consider the following problem:
<Grid HorizontalAlignment="Center" VerticalAlignment="Center" Width="30" Height="100">
<Button Content="This is my button"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Width="100"
Height="30"
RenderTransformOrigin="0.5,0.5">
<Button.RenderTransform>
<RotateTransform Angle="90" />
</Button.RenderTransform>
</Button>
WPF seems to draw the grid, draw the button (with the sides cut off) and then rotate the button (without sides).
Has anyone encountered this problem before?
Shane
|
|
|
|
|
Try LayoutTransform instead of RenderTransform.
|
|
|
|
|
|
Hi,
I am planning to move my VBA/Excel application to WPF or WinForm C#, and adding some cool features. Basically I would like to load a map from google/Bing or manually, draw lines (pipe network) and after make some calculation on these lines. Until now I use several programs to do that Autocad for drawing, Excell for calculation etc.
There are already a lot of apps doing some part of what I want to achieve. Google Map for drawing lines on map, EPANET free framework for pipe networks - but no examples how to integrate its features into C#. Also, commercials editions WaterCAD of Bentley and ArcGIS.
So my question is … will WPF relief my pain or should I stick with WinForm to achieve the above?
|
|
|
|
|
I have a ListBox with a custom item template, as follows:
<ListBox x:Name="AheadListBox"
FontSize="20"
BorderBrush="Transparent" BorderThickness="0,0,0,0"
Background="Transparent"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollBarVisibility="Hidden">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Ellipse Grid.Column="0" Width="20" Height="20"
VerticalAlignment="Top"
HorizontalAlignment="Left"
Margin="5,0,0,0">
<Ellipse.Fill>
<RadialGradientBrush GradientOrigin=".5,.3">
<GradientStop Color="LightSteelBlue" Offset="0.05"/>
<GradientStop Color="DarkBlue" Offset="0.9"/>
<GradientStop Color="DarkBlue" Offset="1"/>
</RadialGradientBrush>
</Ellipse.Fill>
</Ellipse>
<TextBlock Grid.Column="1"
Text="Some really long text string to test the veracity of my XAML Layout. Of course, nothing works the first time where Silverlight is concerned"
Margin="10,0,10,0"
TextWrapping="Wrap" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I want the TextBlock to automatically grow vertically to accomodate all of the text it contains. Things I've tried:
0) At first, I had a StackPanel for a container, but I changed to a Grid to see if that would fix it (no fix was forthcoming).
1) I tried using a Label control instead of a TextBlock .
2) If I manually insert a "\r\n" somewhere in the string, it will grow as expected, but that's not the way the text will be fed to the control.
3) Setting Height="Auto" doesn't appear to have any effect.
4) I also tried calling ListBox.InvalidateMeasure() and ListBox.InvalidateArrange() after the listbox was populated.
5) If I set a hard-coded width for the TextBlock in the XAML, the TextBlock grows vertically as expected.
One other aspect of control (just in case you missed it) - the ListBox is set to expand/contract with its parent container, so the amount of space available to the listbox item will change accordingly.
It's starting to look like I have to do this manually. So much for separating the layout from the business logic...
SOLUTION ===============================
I had to set the horizontal scrollbar to disabled. Once I did that, it bahaved the way I thought it was supposed to.
.45 ACP - because shooting twice is just silly----- "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." - J. Jystad, 2001
modified on Thursday, May 13, 2010 1:17 PM
|
|
|
|
|
Hi,
I am using LINQ to SQL and MVVM pattern in my application where i am retrieving
my data by the following query:
internal ObservableCollection<INVCategory> GetCategoryList()
{
DataLoadOptions dataLoadOptions = new DataLoadOptions();
dataLoadOptions.LoadWith<INVCategory>(t => t.INVSubCategories);
this.Context.LoadOptions = dataLoadOptions;
var categories = from category in this.Context.INVCategories
orderby category.CatgeoryId descending
select category;
return new ObservableCollection<INVCategory>(categories.ToList());
}
And my XAML code for parent(Category) combo is:
<ComboBox Grid.Column="1" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,2,10,2" TabIndex="0" x:Name="categoryComboBox"
ItemsSource="{Binding CategoryList}" IsEditable="True" DisplayMemberPath="CategoryName" SelectedValuePath="CatgeoryId" SelectedItem="{Binding CategoryList, Mode=TwoWay}" SelectedValue="{Binding Path=CurrentEntity.CategoryId, Mode=TwoWay}" >
</ComboBox>
for child(Subcategory) combo i am using:
<ComboBox Grid.Column="1" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,2,10,2" TabIndex="1"
ItemsSource="{Binding SelectedItem, ElementName=categoryComboBox, Mode=OneWay}"
DisplayMemberPath="SubCategoryName" SelectedValuePath="SubCategoryId"
SelectedItem="{Binding INVSubCategories, Mode=TwoWay}">
</ComboBox>
But my child combo items is not populated during form loading as well as parent combo's
selection changed though my parent combo items are populated.
i can't figure out why my child combo is not functioning based on parent combo's
selected item ,please help me.
|
|
|
|
|
Check whether you implemented INotifyPropertyChanged interface for Category class object.
|
|
|
|
|
Thanks Castle Rider for your reply.
I have made a Generic "BasePresenter" class where i have implemented INotifyPropertyChanged interface in the following way:
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = this.PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
And in my Presenter class I have used:
public ObservableCollection<INVCategory> CategoryList
{
get
{
return this.categoryList;
}
set
{
this.categoryList = value;
OnPropertyChanged("CategoryList");
}
}
|
|
|
|
|
Try adding UpdateSourceTrigger=PropertyChanged along with the ItemsSource Binding xaml.
|
|
|
|
|