WPFToolkit:Split button dropdown button disable button - wpf

I am using WPF split button which is inherited from
xmlns:extToolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"
The issue is I want to disable , the button ' the one below(Right side of Button 'Conf' in below 'downarrow present in the below fig) , If user clicks on Left side of the button the rightside should be disabled and the button(leftside) background should change to yellow.please find below the xaml , I am using the wpf split button , dropdown content in this case .please let me know if you have any idea
<extToolkit:SplitButton x:Name="ABCbutton"
VerticalAlignment="Center"
Command="{Binding ACommand}"
FontSize="16>
<TextBlock HorizontalAlignment="Center"
IsEnabled="{Binding IsEnabled, ElementName=AButton}"
Text="A"/>
<extToolkit:SplitButton.DropDownContent>
<StackPanel>
<Button Command="{Binding BCommand}"
Padding="3"
Style="{DynamicResource
DropDownButtonMenuButton}">
<TextBlock Margin="0,3,6,3"
Text="B"/>
</Button>
<Button Command="{Binding BCommand}"
Padding="3"
Style="{DynamicResource
DropDownButtonMenuButton}">
<TextBlock Margin="0,3,6,3"
HorizontalAlignment="Stretch"
Text="C"/>
</Button>
</StackPanel>
</extToolkit:SplitButton.DropDownContent>
</extToolkit:SplitButton>

In a case like this, you will likely be better off creating your own control. The split button can't really handle what you are talking about without a good deal of modification.
Essentially your new control will consist of two buttons, visually styled so that they look like they blend together. Each will have it's own background and enabled property. Add a ViewModel to help control behaviors and set properties, and I think you would be in business. Keep in mind that all of the controls that are supplied in any of the toolkits, frameworks, control packs, etc are made with the primitive types of drawing and framework elements (line, rectangle, border, content presenter, panel, etc) with specialized behavior code.
I end up making a lot of custom controls just because there is not one that perfectly replicates what I want.

Related

Button/Image Switch resource using click, MouseEnter and MouseLeave

I'm trying to change an image using events like Click, MouseEnter and MouseLeave. In first place I tried to do it with Buttons in order to have "Click" event too, but I don't know how to remove that lightblue background that appears by default when I put the mouse over the button with a png background.
After this, I tried to use , setting the resource image.png in its Source.
The main problem is that I don't know what to do in code-behind to change between Image Resources in order to change the Source of the control.
I want to know too if I can use a "Click Event" with an control
Update1:
Ok, I tried it by using Binding
For now I think its solved, but I have another problem.
I don't know exactly how to remove that "border". I tried to put the borderbrush property of the buttons to 0, but it seems to be another property or another control.
UI
Thanks.
You can put an image as the content of a button, and add an Click event to that Button. This way, an event gets called when you press the button.
<Button Margin="0,10" Name="mainButton" Click="mainButton_Click">
<Button.Content>
<Image Source="C:/reference-to-image" Height="30"/>
</Button.Content>
</Button>
In the background you can than change the Picture.
This question shows how to do that in the background.
WPF Image UriSource and Data Binding using http:\\ URL
PS. If you want to change the behavior of controls on certain events things like pressing the left mouse button on it, you have to overwrite the event triggers using
<Style TargetType="TextBlock">
<Style.Triggers>
<EventTrigger RoutedEvent="MouseEnter">
<EventTrigger.Actions>
...
Hope this helps.
UPDATE
You can set the BorderThickness to 0 and than set the Value of the Padding Property to 0. The Button Control has a predefined padding value, which makes it look like it has a border.
Padding is the space inside the control and the content e.g the space between the button and the picture
<StackPanel Orientation="Horizontal">
<Button Click="Button_Click" Padding="0" BorderThickness="0">
<Image Source="link-to-pic" Height="100"/>
</Button>
<Button Click="Button_Click" Padding="0" BorderThickness="0">
<Image Source="link-to-pic" Height="100"/>
</Button>
</StackPanel>

Create/Modify new WPF UI components

I want to change the graphical UI elements in WPF.
For example, I want to use a kind of a stack panel, but on the other hand I want to show my details in a star, or circle, etc.
Maybe setting a bitmap as a background, but I am working with lots of Data using zoom tool.
I found tutorials, documentation only for changing attributes of "old components", but nothing to make new ones.
Great resource for WPF beginners is www.wpftutorial.net
One of the best idea of WPF is separation of concerns:
UI Control = Logic in Code/XAML + Template
Using templates in XAML we can vary representation without modifying the control.
For example, if there is a need in creation of list of items. Then we can use ListBox control:
<ListBox>
<ListBoxItem>USA</ListBoxItem>
<ListBoxItem>UK</ListBoxItem>
</ListBox>
By default LisboxItem internal part is just binded TextBlock.
Now making UI modification without changing control source code:
<ListBox ImageSource="{Binding PathToSource}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{StaticResource ProjectIcon}"/>
<TextBlock Text="{Binding Path=PropertyName}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
there appears image and text.
If there is a need in creating exclusive control then you can always use Custom Control.
Using raster images (e.g. PNG) is not good point, especially with zoom behaviour. If it is possible better to use vector images, that can be created in XAML or imported from SVG.

Custom scrollviewer template scroll button

I have been working on an issue where I want a scrollviewer whose scroll bar is replaced with a button to scroll left and a button to scroll right. (seperate buttons in different grid locations), however I have been struggling to get my head around it as the scrollviewers quite a complicated control.
Lets say I am creating a new control template for scrollviewer and I want to add an extra button into the template that would scroll the content to the right. How would I hook into the command that moves the horizontalscrollbar right. For example my code might have the following scroll bar and buttons and I want to hook into "horizontalscrollbars" right scroll button.
<ScrollBar x:Name="HorizontalScrollBar"
Grid.Column="0"
IsTabStop="False"
Maximum="{TemplateBinding ScrollableWidth}"
Margin="0,0,0,0"
Minimum="0"
Orientation="Horizontal"
Grid.Row="0"
Visibility="Collapsed"
Value="{TemplateBinding HorizontalOffset}"
ViewportSize="{TemplateBinding ViewportWidth}"
/>
<Button Grid.Column="0"
x:Name="LeftBtnScroll">
</Button>
<Button Grid.Column="2"
x:Name="RightBtnScroll">
</Button>
p.s I don't have access to blend.
You probably won't like this answer, but you'll also have to define a ControlTemplate for the Scrollbar element as well... that is the element that has the Buttons that move the content. You can find the default ControlTemplate for the Scrollbar on the ScrollBar Styles and Templates page on MSDN.
On that page, you'll see a section called ScrollBar Parts. This details the named parts of this ControlTemplate. A named part is an element that the 'code behind' accesses to provide some functionality. When defining a new ControlTemplate, you must include these named parts, or some (or maybe all) of the functionality will not work as expected.
The Buttons in the ScrollBar are the named parts that are of type RepeatButton. However, using this method, you will only be able to define your own version of those RepeatButtons and not add additional ones. The functionality that actually moves the content comes from the IScrollInfo interface and have not been exposed by the ScrollBar control, so you cannot hook additional Button clicks to them.
Failing that, the alternative is even longer... you'll need to define your own custom scroll panel that implements the IScrollInfo interface. In doing this, you can then provide your own custom scroll functionality and arrange everything exactly the way that you want:
<ScrollViewer CanContentScroll=”True”>
<YourXmlNamespacePrefix:YourCustomPanel>
<!--Your Content-->
</YourXmlNamespacePrefix:YourCustomPanel>
</ScrollViewer>
This operation is explained beautifully in chapter 7 of the WPF Control Development Unleashed book... you can find a PDF copy online at http://www.adorkable.us/books/wpf_control_development.pdf. It's well worth a look.
[UPDATE 27/11/2014: Sorry, this link is now broken... you'll have to buy the book to see it now.]

Have two controls set the visibility of another control

Sorry for the title, I just don't know how to explain it in one sentence.
So here is my goal: I need to have a boolean in my ViewModel define the visibility for a control (border).
I know I can achieve this with a BooleanToVisibilityConverter, but there is a little more to it. I want a button on my UI to be shown if the control is not visible. Once that button is pushed, then I want the boolean in my ViewModel to be TRUE and then I want the control to be visible and the button that was just pushed to be collapsed. Once that control is visible, I would like a button within that recently visible control to make the control collapsed and then make the original button visible.
Basically, there are two buttons: 1 to make visible (then collapse itself) and the other is to collapse its container and then make the first button visible.
I am trying to do all this with MVVM so if I can avoid code behind in my View that would be ideal!
Since you're using ICommands on your viewmodel, this should work...Assume your commands are "ShowBorderCommand" and "HideBorderCommand" and the property on your viewmodel is "ShowBorder"
<ConverterNamespace:BooleanToVisibilityConverter x:Key="BoolToVis"/>
<ConverterNamespace:ReverseBooleanToVisibilityConverter x:Key="BoolToCollapse"/>
<Border Visibility="{Binding ShowBorder, Converter={StaticResource BoolToVis}}">
<Button Command="{Binding HideBorderCommand}"/>
</Border>
<Button Command="{Binding ShowBorderCommand}" Visbility="{Binding ShowBorder, Converter={StaticResource BoolToCollapse}}"/>
My WPF Converters library has a BooleanToVisibilityConverter that allows reverse conversions, as well as allowing the use of Hidden instead of Collapsed:
<con:BooleanToVisibilityConverter x:Key="ReverseBooleanToVisibilityConverter" IsReversed="True"/>
<Button Visibility="{Binding SomeProperty, Converter={StaticResource ReverseBooleanToVisibilityConverter}}"/>

Dialog form in wpf change content

I want to display a dialog form for new and edit actions... However title, buttons , and few other things should change.
I am wondering how i could implement this. Provide an enum value at constructor ? Like Mode.New or Mode.Edit ? Is there a way to avoid writing code like spNewButtons.Visibillity=Collapsed .. etc , and put it inside wpf ?
You can bind visibility with your mode property, and create a specific IValueConverter to convert the mode to a proper Visibility value. ie:
<StakPanel Visibility={Binding Mode,Converter={StaticResource myProperConverter}}></StackPanel>
Usually my WPF dialogs are all ContentControls that get displayed in a Popup.
My code usually looks like this:
<Grid Name="RootPanel">
<!-- Other Content -->
<!-- Popup is always last so it gets displayed on top of other contnet -->
<local:PopupPanel
local:PopupPanel.PopupParent="{Binding ElementName=RootPanel}"
local:PopupPanel.IsPopupVisible="{Binding IsPopupVisible}"
local:PopupPanel.PopupEnterKeyCommand="{Binding SaveCommand}"
local:PopupPanel.PopupEscapeKeyCommand="{Binding CancelCommand}">
<DockPanel>
<!-- Header -->
<Label DockPanel.Dock="Top" Content="{Binding PopupHeader}" />
<!-- Buttons -->
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Center">
<Button Content="Save" Command="{Binding PopupSaveCommand}" />
<Button Content="Cancel" Command="{Binding PopupCancelCommand}" />
</StackPanel>
<!-- Actual content displayed is determined by DataTemplates -->
<ContentControl Content="{Binding PopupContent}" />
</DockPanel>
</local:PopupPanel>
</Grid>
I removed a lot of the styles to make this easier to read, but you can see the general idea of how it's put together. My ViewModel usually contains properties for IsPopupVisible, PopupContent, and PopupHeader, and commands for PopupSaveCommand and PopupCancelCommand
I use my own custom popup in most cases, although the same thing could be done with a WPF popup.

Resources