I have an application that should work a bit like a message board: text gets parsed, hyperlinks are made "live" and displayed. Only it's in Silverlight. Because of that, I can't use TextBlock like they do here WPF - Making hyperlinks clickable, somehow it's different in Silverlight and it's not possible to do a Hyperlink with a Run inside it.
I've tried the RichTextBlock, as it says here Wrapping Text and Hyperlinks in Silverlight, but couldn't for the life of me figure out how to create the paragraphs and hyperlinks from code, since I need to populate it dynamically.
Then I thought I'd settle for a less elegant solution involving TextBlocks and HyperlinkButtons in a WrapPanel. I added a namespace reference, like it says here WrapPanel in Silverlight 4 toolkit, but when I reference it in XAML, there's no WrapPanel in it, only DataField, DataForm and VisualStateManager.
This Text areas and hyperlinks? doesn't work either, the Silverlight RichTextBox is different and LinkLabel is missing.
Maybe there's another solution that I don't know? I'm keeping an open mind. Any help appreciated.
Related
I am working on new WPF/MVVM project, where I see all most all controls are written for different needs, right from textbox to treeview. All are rewritten for simple need, for example, grid,stackpanel control are rewritten to add space between each item and textbox is rewritten to include label for it so that it has both label and text input are on itself.
My question : Is there any serious issue we would encounter because of this customization?
Already, I am seeing issues with aligning all controls, will i would see any more issues because of this?.
You should never create a custom or user control to add margins, a label to a TextBox, or a new ItemTemplate to a ListBox.
UserControls are for grouping frequently used combinations of controls into one reuseable control. An example may be a custom List-of-Values control that opens a dialog. This would be fine to implement as a UserControl.
Custom controls are good when a native control does not suit your needs. Say that you want to reimplement a DateTimePicker from scratch because the native one doesn't include milliseconds.
There are no serious issues as such, but you may find yourself maintaining all these controls for the next many years without there being a need to do so.
Settings Margins should be done in the View where you are using it, or on a Style in a ResourceDictionary.
This is of course only my opinion (and that of many others, I except), but if you find that the majority of your controls are 'customized' this way, you are doing it wrong.
Style and Templates rather than UserControls and custom controls.
The main issue is that you lose the ability to alter margins only in a single view. If you change your custom controls' inner paddings and margins, you will be changing all the views in your solution. If you use a style, you can always override it by defining a new style in the view, or by setting the property directly.
I am really bad when it comes to styling in XAML and I have a really big problem. I want to customize my scrollviewer in the ListBox that I have. I want to look something as simple as this
I hope that someone can help me do this.
Thanks in advance.
If you're using Expression Blend this is pretty simple actually. First you need to get to your Control Template for your ScrollBar. You can do this by dropping a ScrollBar control on your Design Surface then right-click and choose "Edit Template -> Edit A Copy" which will present a box to enter the name of your new Style Template and whether you want to save it to a Resource Dictionary or to the file you're working in.
Once you have saved it you should see multiple Parts in your Objects & Timeline panel for the Vertical & Horizontal templates of your ScrollBar. You will be editing the properties of the Rectangles & Borders that create the visual of your Scrollbar within each Control Template for Horizontal & Vertical depending on which you choose to use.
To re-create your example should be relatively easy with finding the "VerticalThumbTemplate" or "HorizontalThumbTemplate" and editing the Border / Rectangles within them to get your oval as you display. You might also want to tinker with your VisualStateManager States while you're in there for MouseOver effects etc.
An example of a custom scrollbar can be found in a partial theme I created awhile back you can view here.
Once you have created your custom ScrollBars you can either make your new style template the default by changing the BasedOn Value for that TargetType, or applying it directly to the ScrollViewer built in to your ListView Template.
Hopefully this should be enough to get you started in the right direction. Cheers! :)
Scrollbar is one of the harder template to customize. If your are really bad at that, you maybe have to search at a custom controls librarie.
But if you really want to edit the scrollbar template, there is plenty of sites that will help you with a simple google search
Textbox and RichTextbox are look like same.But don't know the difference.Please tell me anyone, When i have to use TextBox and RichTextbox as well in wpf.
See this Microsoft overview of the differences between a TextBox and a RichTextBox.
From above Link:
Both RichTextBox and TextBox allow users to edit text, however, the two controls are used in different scenarios. A RichTextBox is a better choice when it is necessary for the user to edit formatted text, images, tables, or other rich content. For example, editing a document, article, or blog that requires formatting, images, etc is best accomplished using a RichTextBox. A TextBox requires less system resources then a RichTextBox and it is ideal when only plain text needs to be edited (i.e. usage in forms).
A RichTextBox mainly used if you want more control over styling the text color, type, font, alignment ect. So anything you can do in Microsoft Word, you can do with a RichTextBox.
It can be used to save or display .rtf files with ease.
A Textbox is basically used to display or get one line input. You can have a multi-line TextBox which is used mainly to display or get more than one one-liner and keeps you from having to
manage multiple TextBox's. Also keeps your UI a little more tidy.
So basically the main difference is in styling. If you just want something plain and simple, use TextBox. If you want something fancy, eg styles, colors use a RichTextBox.
Have a look at this:
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/a06ab05a-fbde-47ef-89c5-a7a57f32ffd3
A lot has been said about the differences in the controls' usage scenario.
An important technical difference is that TextBox supports DataBinding, RichTextBox does not, which makes it a bit nasty to use in an MVVM application. If you want a RichTextBox with DataBinding facilities, check out the extended WPF Toolkit on CodePlex.
I have a WPF app with a few Tabs. I'm now messing around with styling and have for example changed the ControlTemplate so I now have to define everything about the TabItem.
Now the TabItem that is selected seems detached from the document below because of some thin line around that content (there is no border). I'm not sure what technique to use to make it look attached again.
My guess would be that the Header-template is responsible for the problem. You can style that too tho - see this example for details: http://www.switchonthecode.com/tutorials/the-wpf-tab-control-inside-and-out
So I'm just starting out with WPF, and I'm really annoyed by the fact that if I lay two Grids on top of one another, the top Grid isn't opaque. It makes designing extremely annoying. Can this be turned off somehow?
I'm just building your standard Winforms STYLE application, but in WPF. I'm just trying to start bridging the gap here. In Winforms(and VB) you'd always have group boxes or something on your form, and then depending on some user context, one of those group boxes would be on top. Its how I've designed forms since time immemorial. One of two things must be true here:
A) This is not the recommended way to design Windows going forward with WPF, but I don't understand what you're supposed to do
B) There is some property to make the Grids opaque so I can build the Window in the style that I'm used to.
I'm fine with answers that solve either A or B. If I'm not doing things the right way because they've changed, then please enlighten me.
Update: So it turns out, I can make the grid opque by setting the background color, but now it seems like I'm locked into a White background as opposed to sticking with the system colors.
You could use SystemColors to make the control background colour match (rather than being white).
I don't understand why you want to put one grid on top of another though. In WPF you generally use a single grid to stack multiple visual elements within one region. Can you explain why you want to hide things in the background with foreground elements?
It sounds a little like you're implementing a tab control -- switching between pages of controls depending on focus. Have you experimented with the new TabControl?
I'm moving from WinForms to WPF development wherever possible and have found that in doing so it's taken some readjustment. WPF has a completely different way of laying things out and now that I'm more comfortable with it, I think it's superior. I'm guessing you just need to ride the learning curve a little longer.
Hope that helps.
EDIT: In response to your comment, I imagine you can have a tab control without tabs, though I haven't tried it myself (might be worthy of another question on SO). Tab controls are headered controls, meaning that they have a header item and a content item. In this case, the header is the tab button, the content is the page item. You can specify a ControlTemplate that details how these items should be displayed relative to one another.
Interestingly, many other types of common GUI element are also headered controls:
Menu items - The menu item text/icon is the header, and the optional submenu is the content
Tree view - Each node is the header, and optional children are within the content
Group box - The header is, well, the header and the content is, well, the content :)
Note that in the case of menu items and tree views, the type may recursively nest within itself. This is quite elegant and can give some wildly different presentation options over the same logical model with only changes to the control template.
For more information read about HeaderedContentControl and HeaderedItemsControl
You could use the following:
<Grid Background="{DynamicResource {x:Static SystemColors.WindowBrush}}">
<!-- content -->
</Grid>
This will respond to changes in the system colors on the fly (the DynamicResource does this).