Drop shadow effect on a HyperLink - c#

I can't seem to find how to add a drop shadow to a hyperlink in a flow document. Since HyperLink is not a UIElement it has no Effect property (all my googling led me to DropShadowEffect). It does have a TextEffects collection but I can't seem to figure out how to create a drop shadow with that. Ultimately what I would like to do is add a dropshadow to the background brush not to the text itself.
My requirement is pretty vague, I just have to make the focus appearance look better (i.e. tab focus and keyboard focus, not mouse over), and I thought a light drop shadow would do the trick, but I'm open to other suggestions.
(I don't have enough rep to upload a screenshot grr so here's a simulation)
There is a HyperLink here
I would like to add a drop shadow around the gray part (light blue in my app) not the text (as mentioned before).

I am pretty sure you can't do this on a per-inline basis. The way WPF provides effects is it applies them wholesale to a single object in the visual tree. Content elements like a Hyperlink are all combined into a single visual element in their parent (the FlowDocumentReader or comparable).
FlowDocument controls do have the ability to host child visual elements using the BlockUIContainer block content element, or InlineUIContainer inline content element. You can use this to apply a DropShadow to a single Hyperlink like so:
<FlowDocument>
<Paragraph>
<Run Text="This is a" />
<InlineUIContainer>
<TextBlock Background="#FFCDCDCD">
<TextBlock.Effect>
<DropShadowEffect ShadowDepth="3" Color="#FFC9C9C9" />
</TextBlock.Effect>
<Hyperlink><Run Text="hyperlink" /></Hyperlink>
</TextBlock>
</InlineUIContainer>
</Paragraph>
</FlowDocument>

Related

Let user resize control (textbox, specifically) in Canvas UWP

I have a canvas with a button that the user can press to add a new textbox to the canvas. How can I make it so the user can resize the text box by clicking and dragging on any of the corners of the textbox. Because the textbox is created in the C# code (not XAML), I would prefer code in C# not XAML.
Thanks
EDIT: My question is different than the one referenced because it is in UWP not WPF. These have very different controls. I would appreciate if you could translate the UWP information into UWP C#
You can use Thumb control instead of a textbox. The thumb control provides the functionality for you to write code to customize the drag and drop behavior. A simple code would be:
<Canvas x:Name="test">
<Thumb Width="100" Height="100">
<Thumb.Template>
<ControlTemplate>
<TextBlock HorizontalAlignment="Center" Text="12345"/>
</ControlTemplate>
</Thumb.Template>
</Thumb>
</Canvas>
A more complex sample could be found from this SO thread from Jay's answer. But please notice you need to customize the logic yourself in order to make it resize like what you need. The reference is just a direction.

Most simple FrameworkElement to handle HorizontalAlignment and VerticalAlignment?

This is Silverlight.
Initial goal is to display a random element in a Popup with some VerticalAlignment and HorizontalAlignment. I do not want to use VerticalOffset or HorizontalOffset, because there is more to what I really want to do, including some complex bindings.
First attempt was:
<Popup>
<Button
Height="135"
HorizontalAlignment="Stretch"
VerticalAlignment="Bottom" />
</Popup>
Second attempt was:
<Popup
Height="135"
HorizontalAlignment="Stretch"
VerticalAlignment="Bottom">
<Button />
</Popup>
Both were a failure: the Button was always on Top and not Stretch (HorizontalAlignment and VerticalAlignment didn't work).
So I had the idea to encapsulate the element in a simple FrameworkElement:
<Popup>
<Border>
<Button
Height="135"
HorizontalAlignment="Stretch"
VerticalAlignment="Bottom" />
</Border>
</Popup>
And it is working.
But I had to use Border in this example, when I could have done it with Grid and many other FrameworkElement (but not with Canvas or Viewbox or Popup). I'd like to know what is the most simple, efficient and processor-friendly transparent FrameworkElement to encapsulate another element with working HorizontalAlignment and VerticalAlignment? Is it:
Border? (like the above example)
UserControl?
ContentControl?
ContentContainer?
some custom and basic MyFrameworkElement? (might need help for most basic implementation)
something else like Grid?
WPF controls come in two flavors: Ones that interact with users (like accept user clicks like a button, or display text like a text block) and containers that control placement and layout of the previous ones.
Container controls are usually designed to lay out their children in a specific manner. For example, Canvases lay out children by X, Y, Width & Height values. Each one has a specific use, so you must read the documentation or tutorials for these container controls and understand how each works in order to select the appropriate one for a task.
In your case, you want the button to fill all available space in the popup (it seems, it isn't that clear). I know that the Grid does this by default. So I would do the following:
<Popup><Grid><Button /></Grid></Popup>

Adding elements to a panel in c#!

quick question, in a c# Windows Presentation Foundation How can i add some elements to a Panel so i can easily hide all the elements (Text, Labels...) by just hiding the panel it self?
I have already tried to just put panels over the elements to hide them but i don't think that would be a neat solution because i would also hide all the other elements under it.
I need this because i am trying to have different forms in the same place and on the base of what the user types the items should appear. I don't want it to open a new window.
Thanks!
Assuming all your elements are in the same container, just set the Visibility property of the container to "Collapsed". Ideally, this would be by binding to a bool and using the BoolToVisibility converter provided in WPF.
If they are NOT in the same container, you are a bit out of luck. You will need to set/bind each of the element's visibility properties separately, but using the same techniques as above.
If you place all of the elements you want on that panel you can tell that panel to be invisible or visible and all of the elements on that panel will hide or show accordingly. For ease of use when you are programming you can right click on the panel and choose send back or bring forward and this will help you navigate your form while programming.
Panel is a base class and has a Visibility property
Panel Properties
<StackPanel x:Name="pnl1" Grid.Row=0 Visibility="Collapsed">
<TextBlock x:Name="tbTime" />
<TextBlock x:Name="tbDate" />
</StackPanel>
<StackPanel x:Name="pnl2" Grid.Row=2 Visibility="Visible">
<TextBlock x:Name="tbTime2" />
<TextBlock x:Name="tbDate2" />
</StackPanel>

Right justify InputGestureText og menuitem

DO you have any idea on how to right justify a menuitems InputGestureText?
My menu's InputGestureText will always display left-justified just like this:
File
New...............Ctrl+N
Open.............Ctrl+O
Options.........Alt+Enter
Exit................X
What I'm trying to do is to display it like this:
File
New.......................Ctrl+N
Open....................Ctrl+O
Options.............Alt+Enter
Exit...............................X
I tried doing InputGestureText.PadLeft() but my font-family is proportional so it will still result to
File
New ............Ctrl+N
Open...........Ctrl+O
Options......Alt+Enter
Exit..................X
I tried to research some ways to make it possible but no luck.
You have to modify the style of the menu item.
It should be sufficient to copy it and just change the alignment on the element with the name
InputGestureText, we use a ContentPresenter instead of a TextBlock, but both should work.
<ContentPresenter
Grid.Column="2"
Margin="16,0,6,0"
x:Name="InputGestureText"
Content="{TemplateBinding InputGestureText}"
HorizontalAlignment="Right"
VerticalAlignment="Center"/>
You could probably change the Template of menu items via a Style so that the container of that section aligns its content to the right.

WP7 App: Too large page

I have created a small WP7 app which contains one page which is dynamically filled with content. But it goes out of viewable area. Emulator doesn't scroll the page when I click-hold-move on the screen. How do I make it scroll when needed?
One simple option is to drop the content you require inside a ScrollViewer, so for example adding a large TextBlock as so:
<ScrollViewer Name="scrollViewer" ScrollViewer.HorizontalScrollBarVisibility="Visible" >
<TextBlock Height="30" Name="textBlock" FontSize="24"
Text="This is a long block of text which wont fit in the available area" />
</ScrollViewer>
Obviously, in most cases you will want to drop a container control such as Grid or StackPanel into the ScrollViewer and place all your other controls in there.
That said, I'm wondering if you are actually looking for some of the standard WP7 Metro look and feel controls such as the Panorama and Pivot Controls which are available in the latest dev tools - follow that link for full details.

Categories

Resources