Avalon Edit Cut\Copy\Paste Commands from MahApps.Metro Button - mahapps.metro

I'm implementing a custom simplified editor in WPF using AvalonEdit and MahApps.Metro. I am stuck trying to get the cut/copy/paste/undo/redo commands working using MahApps.Metro icon/circle buttons instead of a toolbar.
The AvalonEdit sample uses a toolbar, and if I add a similar toolbar to my current application, it works as expected.
I want to call the Cut/Copy/Paste from a series of icon buttons on my app layout instead of inside a toolbar. My MahApps.Metro buttons are as follows. I've tried it with and without the Command Target set. In both cases nothing happens when I click them.
<Button Width="48"
Height="48"
Margin="24,0,0,0"
Style="{DynamicResource MahApps.Metro.Styles.MetroCircleButtonStyle}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Command="Undo"
CommandTarget="{Binding ElementName=xmlTextEditor.TextArea}">
<iconPacks:PackIconMaterial Kind="UndoVariant" />
</Button>
I'm relatively new to WPF so I might be missing something really basic here. Any help is appreciated.

Related

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.]

Having difficulty using Z-Index in WPF

I've followed some examples trying to layer a rectangle over the WebBrowser object:
Here is the MSDN example link. (I got it to work)
Layers issue using Z-Index
Here is the code I'm trying to get to work:
<Grid>
<Canvas Margin="2,4,0,-450" >
<Rectangle Height="452" Canvas.ZIndex="1000" Name="rectangle1" Stroke="Black" Width="524" Opacity=".5" Fill="#8CBABABA" Canvas.Top="-7" Canvas.Left="-3" />
<WebBrowser Name="mapBrowser" Canvas.ZIndex="999" Margin="5,5,5,5" Height="452" Width="516" Canvas.Top="-11" />
</Canvas>
</Grid>
I'm trying to make the WebBrowser appear grayed out by making the rectangle appear over top of it. I'll also disable it.
Can anybody point to what I'm doing wrong?
I solved this issue by creating a .png image which I placed in the same space as the webbrowser. It looks like a grayed-out version of what first appears in the webbrowser. Then I conditionally hid the webbrowser which makes the image visible. This is the only way I've found to make it work using .Net 4.0.

ImageButton in Silverlight 3?

For our .NET project this year we have to create a website in Silverlight.
Now I have been getting along nicely utilizing the grid, making gridrows and colums, but I have got to the part where I have to create navigation buttons.
So I decided to go for the following look of the buttons:
Now, when I add a button to my project and I give it the background of that image, this happens.
I have looked at other methods to create an image button but those involve putting an image INSIDE the button using a stackpanel. I tried that and it looks really bad.
This is the code the button generated:
<Button Content="Button" Height="40" Name="button1" Width="125">
<Button.Background>
<ImageBrush ImageSource="/OndernemersAward;component/Images/button.png" Stretch="Fill" />
</Button.Background>
</Button>
I don't know what's going on here and I hope somebody can help me.
Thanks, Thomas
Putting an image inside the button is the best way to go. You can just have an image inside a button, or you could put a StackPanel inside and arrange other content as you see fit. You can also get rid of the border and background brushes on the button so that it is just your image and nothing else. Try this code:
<Button Height="40" Name="button1" Width="125" BorderBrush="{x:Null}" Background="{x:Null}" IsHitTestVisible="False">
<Image Source = "/OndernemersAward;component/Images/button.png"/>
</Button>
That will make a button that is just your image with no other borders, or colors. You can tweak the other settings as you see fit. Note that in order to use the image as the button, you have to delete the Content tag, since the inside of the <Button> takes the place of it.
I ultimately solved this by using blent. I created an image and there is a control there that can transform the image to a button.

Execute command on mouse click on image control wpf

There is a command property in wpf that I am trying to execute on an image click. I am basically changing the style of a scroller. I downloaded sample styles from here and after changing my style I end up with something like:
ok so let me explain. on the top there is an arrow pointing upwards on top of an image. I plan to get rid of the top arrow but the reason why I need it is because in the xaml it has a command that when clicked it scrolls upward. the code for that up arrow is:
<RepeatButton
Style="{StaticResource ScrollBarButton}"
Margin="0,15,0,0"
VerticalAlignment="Top"
Background="#FFFFFFFF"
Grid.Row="0"
Command="{x:Static ScrollBar.LineUpCommand}" <!-- This is the line that enables to scroll upwards when clicked -->
theme:ScrollChrome.ScrollGlyph="UpArrow"
RenderTransformOrigin="0.5, 0.5">
<RepeatButton.RenderTransform>
<ScaleTransform ScaleX="4" ScaleY="2"/>
</RepeatButton.RenderTransform>
</RepeatButton>
In short I am interested in the following property:
Command="{x:Static ScrollBar.LineUpCommand}"
It would be nice if I could get rid of the top arrow and place that command in the image instead. The problem is that the image control does not have the property command. I know I can make the alpha of the top arrow equal to 0 and make it appear like there is only an image but I am curios of understanding how does this work and moreover I would like to add more functionality such as changing the image appearance on mouse enter etc..
Create a button with control template just having an image and bind to the
Command of the button. More on this can be found here:
Attach ICommand in WPF UserControl
Or try using eventtocommand available in mvvm light tookit

How do I make modal dialog for a Page in my WPF-application?

I have a WPF Window which has a among other controls hosts a Frame. In that frame I display different pages. Is there way to make a dialog modal to only a page? When I'm showing the dialog it should not be possible to click on any control on the page but it should be possible to click on a control on the same window that is not on the page.
If I am correct in interpreting your message, you want something that works similar to what
Billy Hollis demonstrates in his StaffLynx application.
I recently built a similar control and it turns out that this sort of idea is relatively simple to implement in WPF. I created a custom control called DialogPresenter. In the control template for the custom control, I added markup similar to the following:
<ControlTemplate TargetType="{x:Type local=DialogPresenter}">
<Grid>
<ContentControl>
<ContentPresenter />
</ContentControl>
<!-- The Rectangle is what simulates the modality -->
<Rectangle x:Name="Overlay" Visibility="Collapsed" Opacity="0.4" Fill="LightGrey" />
<Grid x:Name="Dialog" Visibility="Collapsed">
<!-- The template for the dialog goes here (borders and such...) -->
<ContentPresenter x:Name="PART_DialogView" />
</Grid>
</Grid>
<ControlTemplate.Triggers>
<!-- Triggers to change the visibility of the PART_DialogView and Overlay -->
</ControlTemplate.Triggers>
</ControlTemplate>
I also added a Show(Control view) method, which finds the the 'PART_DialogView', and adds the passed in view to the Content property.
This then allows me to use the DialogPresenter as follows:
<controls:DialogPresenter x:Name="DialogPresenter">
<!-- Normal parent view content here -->
<TextBlock>Hello World</TextBlock>
<Button>Click Me!</Button>
</controls:DialogPresenter>
To the buttons event handler (or bound command), I simply call the Show() method of the DialogPresenter.
You can also easily add ScaleTransform markup to the DialogPresenter template to get scaling effects shown in the video. This solution has neat and tidy custom control code, and a very simple interface for your UI programming team.
Hope this helps!
I have a project on github which is a custom FrameworkElement that allows you to display modal content over the primary content.
The control can be used like this:
<c:ModalContentPresenter IsModal="{Binding DialogIsVisible}">
<TabControl Margin="5">
<Button Margin="55"
Padding="10"
Command="{Binding ShowModalContentCommand}">
This is the primary Content
</Button>
</TabItem>
</TabControl>
<c:ModalContentPresenter.ModalContent>
<Button Margin="75"
Padding="50"
Command="{Binding HideModalContentCommand}">
This is the modal content
</Button>
</c:ModalContentPresenter.ModalContent>
</c:ModalContentPresenter>
Features:
Displays arbitrary content.
Does not disable the primary content whilst the modal content is being displayed.
Disables mouse and keyboard access to the primary content whilst the modal content is displayed.
Is only modal to the content it is covering, not the entire application.
can be used in an MVVM friendly way by binding to the IsModal property.
Why not just use nested message pumps to create modal controls
http://deanchalk.com/wpf-modal-controls-via-dispatcherframe-nested-message-pumps/
You are not looking for a modal dialog here. You need a function that will disable the "page" control, show a dialog, and re-enable it when the dialog closes.
I'm not too sure whether you understand what a modal dialog is meant to do though?

Resources