|
You were right, did not need all of those properties. I see your point about the SelectedDefect, but it is ok to leave it blank when the user changes the category as I am relying on IDataErrorInfo to ensure that the user does not leave it blank.
This was the final product (For now):
public Observation SelectedItem
{
get { return _selectedItem; }
set
{
if (_selectedItem == value)
return;
_selectedItem = value;
_selectedCategory = _con.Categories.Where(c => c.id == value.Defect.categoryId).FirstOrDefault();
OnPropertyChanged("SelectedItem");
OnPropertyChanged("SelectedCategory");
LoadDefects(_selectedCategory.id);
}
}
public Category SelectedCategory
{
get { return _selectedCategory; }
set
{
if (value == null) return;
_selectedCategory = value;
OnPropertyChanged("SelectedCategory");
LoadDefects(_selectedCategory.id);
}
View:
public Observation SelectedItem
{
get { return _selectedItem; }
set
{
if (_selectedItem == value)
return;
_selectedItem = value;
_selectedCategory = _con.Categories.Where(c => c.id == value.Defect.categoryId).FirstOrDefault();
OnPropertyChanged("SelectedItem");
OnPropertyChanged("SelectedCategory");
LoadDefects(_selectedCategory.id);
}
}
public Category SelectedCategory
{
get { return _selectedCategory; }
set
{
if (value == null) return;
_selectedCategory = value;
OnPropertyChanged("SelectedCategory");
LoadDefects(_selectedCategory.id);
}
Maybe I should change the _selectedCategory to derive from my AllCategories observable collection instead. Either way, this works. Thank you.
Cheers, --EA
|
|
|
|
|
Glad to help
|
|
|
|
|
I created the following button style. I want to set the image's opacity to 50% when the button is disabled. I have the Image.Style code in there, but how do I bind the IsEnabled to the button? See my comment in line.
<Style TargetType="{x:Type controls:FlatButton}"
x:Key="FlatButtonStyle">
<Setter Property="Height" Value="35"/>
<Setter Property="Width" Value="80"/>
<Setter Property="Margin" Value="2"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:FlatButton}">
<Border x:Name="TheBorder"
Background="Transparent"
BorderBrush="#6F6F6F"
BorderThickness="0"
CornerRadius="2">
<StackPanel Orientation="Horizontal">
<Image Source="{TemplateBinding ImageSource}"
Grid.Row="0"
Grid.Column="0"
Width="16"
Height="16"
Margin="3,0,2,0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Stretch="Fill">
<Image.Style>
<Style TargetType="Image">
<Style.Triggers>
<!--How do I bind to the IsEnabled property on the button?-->
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" Value="0.5" />
</Trigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
<TextBlock Text="{TemplateBinding Caption}"
Grid.Row="0"
Grid.Column="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Margin="10"
Foreground="#5D5D9D"
FontSize="12"
TextWrapping="WrapWithOverflow"/>
</StackPanel>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver"
Value="True">
<Setter TargetName="TheBorder"
Property="BorderThickness"
Value=".5">
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
If it's not broken, fix it until it is
|
|
|
|
|
You just need to add another trigger in the Buttons triggers like so:-
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="TheBorder" Property="BorderThickness" Value=".5"></Setter>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="img" Property="Opacity" Value="50" />
</Trigger>
</ControlTemplate.Triggers>
That assumes that the image control in the style is given a name "img" .
Hope this helps
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
hello all.
I need a tip for good coding. I'm in my first stemps in WPF and i have a srollviewer with button inside that work nice. Now i need to provide another collection of button or another scrollviewer. i mean, the rest of the project dont change, only the scrollviewer.
what is the best way for that?
i hope i explained the issue.
Thanks.
|
|
|
|
|
I am afraid your question is not very clear. Could you try and expand it to make it clearer on what you would like to do.
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
sorry. i will try again.
i have a finished project when i have a scrollviewer with a collection of button inside.
now i want to create the option to open another collection of button in the same project, replacing the old one if the option was select.
in the .cs side i think i can do easly, but maybe, there is a xaml good coding option.
|
|
|
|
|
Create 2 button collections/containers, bind the visibility property to the option control so only 1 is visible based on the user selection.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I'm totally agree with Mycroft Holmes. Don't forget to create a Converter for Visibility Enumeration.
Regards.
Christian Amado
MCITP | MCTS | MOS | MTA
DCE 0★ 1★ 2★ 3★ 4★ 5★
Bronze level MVA
Olimpia ☆ ★★★
|
|
|
|
|
Why? If the property you use to control the visibility is a boolean there is a built in BooleanToVisibilityConverter.
|
|
|
|
|
Pete O'Hanlon wrote: built in BooleanToVisibilityConverter.
What, where, I have one I use in my utils but I didn't know there was a built in one (Silverlight). I also have various NOT converters
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I'm not sure about Silverlight (I mainly stick with WPF), but in WPF 4 you can find details of it here[^]. Most people who worked with pre WPF4 have their own implementation of this control - MS was informed that there should be a default version.
|
|
|
|
|
Hi there. In Silverlight you must apply a converter to Visibility enumeration. Remember that Visibility property is an enumeration not a Boolean =)
Christian Amado
MCITP | MCTS | MOS | MTA
DCE 0★ 1★ 2★ 3★ 4★ 5★
Bronze level MVA
Olimpia ☆ ★★★
|
|
|
|
|
Go back to the start of the thread. The OP stated he was using WPF.
|
|
|
|
|
Ups. Sorry for that.
Regards
Christian Amado
MCITP | MCTS | MOS | MTA
DCE 0★ 1★ 2★ 3★ 4★ 5★
Bronze level MVA
Olimpia ☆ ★★★
|
|
|
|
|
No problem. It's an easy mistake to make.
|
|
|
|
|
Hi,
How can i open secondpage in silverlight on click event of button.
Thanks & Regards
Form :-
Vikash Yadav
Mob : 9210907172
|
|
|
|
|
Hi!
Imports System.Windows.Browser
HtmlPage.Window.Navigate(New Uri("http://zzz-server/zzz/Employees.aspx"), "_blank", "")
|
|
|
|
|
Do some research into navigation (assuming you do not just want an HTML page) here are the results of a search [^]in this forum, plenty of rich pickings in there.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
You can use Microsoft Prism[^] where your main screen is divided into regions.
Views (xamls) can then be removed and added to these regions.
Removing and adding views gives an effect of navigating across the application.
|
|
|
|
|
Hi friends,
I want basic idea how I can achieved sword effect. The one we see in fruit Ninja with which it cut fruits,
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
|
|
|
|
|
I don't have a clue, but the subject is funny.
Watched code never compiles.
|
|
|
|
|
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
|
|
|
|
|
http://www.fruitninja.com/[^] might be what he was talking about
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Ok, I finally got my treeview with hyperlinks working. Thanks SledgeHammer!
I now have the following
<Window.Resources>
<Style x:Key ="linkStyle"
TargetType="{x:Type Hyperlink}" >
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="TextBlock.TextDecorations" Value="Underline"/>
<Setter Property="Foreground" Value="RoyalBlue" />
</Trigger>
<Trigger Property="IsMouseOver" Value="False">
<Setter Property="TextBlock.TextDecorations" Value="{x:Null}"/>
<Setter Property="Foreground" Value="RoyalBlue" />
</Trigger>
</Style.Triggers>
</Style>
<HierarchicalDataTemplate DataType="{x:Type models:NodeModel}"
ItemsSource="{Binding Path=Children}">
<StackPanel Orientation="Horizontal"
Margin="2">
<TextBlock>
<Hyperlink NavigateUri="{Binding Caption}"
Foreground="#0C2DAA"
Style="{StaticResource linkStyle}"
CommandParameter="{Binding}"
Command="{Binding Path=DataContext.SelectedLinkCommand,
RelativeSource={RelativeSource FindAncestor,
AncestorType={ x:Type views:MainWindowView}}}">
<InlineUIContainer>
<TextBlock Text="{Binding Caption}" />
</InlineUIContainer>
</Hyperlink>
</TextBlock>
</StackPanel>
</HierarchicalDataTemplate>
</Window.Resources>
<Grid>
<controls:TreeViewEx ItemsSource="{Binding TreeData}"
SelectedItemEx="{Binding SelectedTreeItem, Mode=TwoWay}"
Grid.Row="0"
Grid.Column="0">
<TreeView.Resources>
<!--Make the selected item's background transparent-->
<SolidColorBrush Color="Transparent" x:Key="{x:Static SystemColors.HighlightBrushKey}"/>
</TreeView.Resources>
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
</Style>
</TreeView.ItemContainerStyle>
</controls:TreeViewEx>
</Grid>
I'd really like to have all the treeview styling done in one place, but I'm not sure how. I would like to move
<TreeView.Resources>
<!--Make the selected item's background transparent-->
<SolidColorBrush Color="Transparent" x:Key="{x:Static SystemColors.HighlightBrushKey}"/>
</TreeView.Resources>
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
</Style>
</TreeView.ItemContainerStyle>
out of the treeview up to the Window.Resources section.
If it's not broken, fix it until it is
|
|
|
|