|
There is no List document element in Silverlight 4. So how do you format an itemized list in a RichTextBox? Is there any easy way?
|
|
|
|
|
Hey, What do you mean by itemized list in a RichTextBox?
Don't forget to Click on [Vote] and [Good Answer] on the posts that helped you.
Regards - Kunal Chowdhury | Software Developer | Chennai | India | My Blog | My Tweets | Silverlight Tutorial
|
|
|
|
|
KunalChowdhury wrote: What do you mean by itemized list in a RichTextBox?
I don't understand your question. Surely you aren't asking me what an itemized list is, are you?
It doesn't matter anyhow. There is no way to do it. I just expected it to be there since the new RichTextBox in Silverlight 4 takes a list of something called Paragraph elements and I just naturally assumed these were the same Paragraph elements that were in WPF, which do take itemized lists. But they only vaguely resemble the WPF Paragraph. They don't even have a Margin property which might be a starting point for rolling your own itemized lists.
So forget it. I learned from a recent Code Camp I went to that Microsoft has given up the idea of ever supporting flow documents in Silverlight. Instead in a future release of Silverlight they will provide a way of supporting an HTML area within Silverlight content. (They've always supported the opposite: Silverlight content within HTML.) Once that happens, we'll be able to include itemized lists within Silverlight and the user won't even know or care that it's actually HTML that is generating the itemized list.
I guess Microsoft figured it was easier to rely on existing technology rather than reinventing the wheel. Trouble is, they should have done this ages ago. Meanwhile, we have to wait and wait, and in the meantime put up with poorly formatted running text in Silverlight applications.
The syntax for itemized lists in WPF is incredibly verbose anyhow. It will be a blessing to be able to use the concise syntax of HTML for generating itemized lists, and flow documents in general. The only thing is, it will never have the convenience of automatically flowing into multiple columns like WPF, although I am by no means an HTML programmer, so maybe that will be possible, also.
|
|
|
|
|
The RichTextBox in Silverlight 4 supports the Paragraph element. But if you just put two paragraphs in a row together, there is no leading between the paragraphs. Also, unlike WPF, the Paragraph element does not define a Margin property. If the first paragraph just happens to fill the last line (or nearly so), it looks as if there is only one paragraph and there is no visual clue that you actually have two paragraphs.
So how do you control the leading between paragraphs? You get far too much leading if you end each paragraph with a LineBreak element, so that's not a solution, and it's a kludge to begin with.
Solution: The only way to solve this is through a kludge. I bounced this solution off a Silverlight MVP and he thought this kludge was "clever." To provide leading between each paragraph in the BlockCollection of a RichTextBox, you can include markup like the following:
<Paragraph FontSize="4"></Paragraph>
when for example the font size of your paragraphs is 14. If you use the default font size for your paragraphs (11), a font size of 3 might work in the kludge.
modified on Monday, May 24, 2010 3:36 PM
|
|
|
|
|
Thanks for posting a solution here - even though it's a workaround.
My signature "sucks" today
modified on Tuesday, May 25, 2010 2:17 AM
|
|
|
|
|
I have implemented validation using IDialogService on INotifyPropertyChanged but its not working properly when i click on save button and after successfull insertion if i ll clear my control then also my validation message display error message.
if any boday can help me then i ll be thankfull to him.
Reasons are not Important but Results are Important.
http://www.sql4professional.blogspot.com
Swati Tripathi
modified on Saturday, May 22, 2010 5:35 AM
|
|
|
|
|
You need to post code here to show what you have implemented so far before anyone can help you.
My signature "sucks" today
|
|
|
|
|
below is used for binding validation
<TextBox x:Name="txtDispalyName" Text="{Binding Path=DisplayName, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}" Grid.Row="1" Height="24" LostFocus="txtDispalyName_LostFocus" Grid.Column="2" Margin="18,2,54,0" VerticalAlignment="Top" TabIndex="0" >
while in code behind on save click i m calling below code
ViewModel.IsError = true;
getBindProperty();
if (ViewModel.Save())
{
IsSaveClose = true;
SaveData();
}
else
{
ViewModel._dialogService.DisplayValidationDialog(ViewModel.Errors);
}
while my validation class is
public class MyViewModel : INotifyPropertyChanged
{
public readonly IDialogService _dialogService;
CultureInfo Culture;
public MyViewModel(IDialogService dialogService)
{
_dialogService = dialogService;
}
private string _displayName = "";
public bool IsError { get; set; }
public string DisplayName
{
get { return _displayName ; }
set
{
if (string.IsNullOrEmpty(value))
{
Culture = Thread.CurrentThread.CurrentCulture;
IsError = false;
throw new Exception(Erp3s.Resources.Strings.ResourceManager.GetString("Display Name is required",Culture));
}
_displayName = value;
OnPropertyChanged("DisplayName");
}
}
private readonly ObservableCollection<ValidationError> _errors = new ObservableCollection<ValidationError>();
public ObservableCollection<ValidationError> Errors
{
get { return _errors; }
}
public bool IsViewStateValid()
{
return Errors.Count == 0;
}
public bool Save()
{
if (!this.IsViewStateValid())
{
return false;
}
else
{
return true;
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler pceh = PropertyChanged;
if (pceh != null)
{
pceh(this, new PropertyChangedEventArgs(propertyName));
}
}
}
for reference i had referred http://www.thejoyofcode.com/Silverlight_Validation_and_MVVM_Part_II.aspx[^]
but my problem is when i click on save button and if i will clear my textbox then also this validations are fired.
Reasons are not Important but Results are Important.
http://www.sql4professional.blogspot.com
Swati Tripathi
|
|
|
|
|
Hi,
you might want to consult the help about the VisualTreeHelper class. I think this provides the functionality you're looking for.
If you need further assinstance, please provide some more concrete code/XAML.
Cheers
Jürgen
|
|
|
|
|
Hi,
your problem has nothing to do with WPF; it's about C# fundamentals.
You might want to take a look at the inheritance tree. There you can see why you get that error. Neither Border nor Image derive from Control.
To be honest (really no flaming or insulting intended):
The best advice I can give you, is to take a good book about C#- or .Net basics and a little time.
In case I'm mistaken, I'll give you some clues (which hopefully will only help you if I'm mistaken):
1. ugly solution: use the VisualTreeHelper class.
2. ugly solution: use a common ancestor
3. good solution: use data binding
Both ugly solutions (as well as the provided code) imply that you will never use your own controls - or you'll get an endless list of "if ... GettYpe()". Solution #2 (as well as the provided code) still has to deal with the stacking of WPF objects (you will find the Border inside the Canvas, but you will not find the TextBox inside the Border).
Unfortunately I can't recommend any C# book, but if it's up to WPF (and accordingly data binding), I've learned a lot from "WPF unleashed".
Cheers
Jürgen
|
|
|
|
|
Hema Bairavan wrote: if(ctr.Gettype() == tx.Gettype())
Why dont you just put in a condition to check for and avoid a border .
foreeach(control ctr in OuterCanvas.controls)<br />
if(ctr.Gettype() == tx.Gettype() && ctr.Gettype() != System.Windows.Border)<br />
((TextBox)ctr).text = "";
My signature "sucks" today
|
|
|
|
|
How do you color a rectangle in C# that has been declared in XAML in WPF?
There is a rectangle control in XAML. In my C# code there are times in which it would be nice to fill the background color. How does one do this?
|
|
|
|
|
The way I'd do it is bind the Rectangle background colouur to a property and use INotifyPropertyChanged to trigger the update of the colour based on the change.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
How do I bind the Rectangle background colour to a property?
|
|
|
|
|
In your XAML:
<Rectangle
Width="200"
Height="100"
Fill="{Binding Path=BoundColour}"
Stroke="Black"
StrokeThickness="4" /> This assumes that you have a property called BoundColour.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
The problem I am having is that there is a textblock inside the rectangle. When I do a Fill, the textblock is erased. Will this binding suggestion fix this problem?
|
|
|
|
|
How do you send a refresh message to a WPF grid or canvas?
In other words, I have noticed while in debug mode, I can write code that sends a line to the display and then, if that line is not right, I can adjust it -- but the previous line is still there.
Now, the code I am writing sends information to the display based on what the user clicks. So this must mean that the display is not refreshed each time a new set of lines and boxes and text goes to the grid or canvas in WPF.
Using C# code, how do you send a refresh/repaint message to a WPF grid or canvas?
|
|
|
|
|
Hi,
although I'm not sure about your saying "...code that sends a line to the display...", I'll try to answer, as far as I've understood:
The "UIElement" class has a method "InvalidateVisual", which will force a complete new layout pass; Grid and Canvas derive from "UIElement" and thus have this method available. But this is a rather expensive (considering performance) way to 'refresh the screen'.
If you have a TextBlock or TextBox for the "line" in your container (Grid or Canvas), you could give it a name (in the VS designer) and access the "Text" property from code. This would work just as in WinForms. This assumes, that you know your control at design time.
The easiest and most WPF-like (and to me the only correct) way, is to bind the "Text" property of the textcontrol to a string property (say: MyText) of an object (say: class MyData) used as the container's "DataContext". The "MyData" class must implement the interface "INotifyPropertyChanged" and the "MyText" setter must fire the "PropertyChanged" event.
Now every change to the "MyText" property will be automatically be reflected in the textcontrol.
Hope this helps to get you on the right track.
Cheers
Jürgen
|
|
|
|
|
I'm using a data bound treeview. I have added a dot next to each treeviewitem:
<HierarchicalDataTemplate DataType="{x:Type local:RuleGroup}" ItemsSource="{Binding Path=Rules}">
<StackPanel Orientation="Horizontal">
<Image Source="/RulesEngineUI;component/Media/bluedot.png" Height="8" Width="8" Margin="0,0,3,0"/>
<TextBlock Margin="0,0,5,0" FontWeight="Bold" >Group:</TextBlock>
<TextBlock>
<Hyperlink Name="Link" Style="{StaticResource LinkStyle}" Click="Link_Click">
<TextBlock Text="{Binding Path=GroupName}"></TextBlock>
</Hyperlink>
</TextBlock>
</StackPanel>
</HierarchicalDataTemplate>
Now I want to be able to change that image at runtime in the code behind.
How do I get a reference to the image?
Everything makes sense in someone's mind
|
|
|
|
|
You don't. The correct (WPF) way to do this is to have the image as a bound item and update the bound version, and this will update the UI.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Got an example of that?
Everything makes sense in someone's mind
|
|
|
|
|
Hi All,
I am currently facing problem with the usage of 2way binding in Wpf.
Here is my problem
I have 1 Model class and a view model class and a view to render data from view model.
I am using the ObjectDataProvider for databinding in View.
I have a method in view model which will give me the List of data (of type model).
Now I am showing this list in a ItemsControl in view with datatemplate applied.
Here is my ItemsControl:
<ItemsControl ItemsSource="{Binding Source={StaticResource ResourceKey=F1TeamsList}}" ItemTemplate="{StaticResource ResourceKey=F1TeamViewTemplate}"/>
I have 2 text box in datatemplate and I have specified twoway binding there.
<ObjectDataProvider x:Key="F1TeamsList" ObjectType="{x:Type f1teamvm:F1TeamViewModel}" MethodName="GetF1Teams"/>
<DataTemplate x:Key="F1TeamViewTemplate">
<StackPanel>
<TextBox x:Name="teamDriver1Box" Text="{Binding Path=TeamDriver1}"/>
<TextBox x:Name="teamDriver2Box" Text="{Binding Path=TeamDriver2}"/>
</StackPanel>
</DataTemplate>
Here F1TeamList - is the objectdataprovider which returns list and F1teamViewTemplate is datatemplate.
And GetF1Teams is the function which provides me list.
But this code is not working as expected. It fetches data properly but 2way binding is not working here
Any Idea??
Regards
|
|
|
|
|
How have you defined the TeamDriver1 and TeamDriver2 properties? Are they raising the PropetyChanged event (the class must implement INotifyPropertyChanged for this)?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Yes I have implemented the INotifyPropertyChanged interface in the Model class.. And the two properties are raising the PropertyChanged event.
|
|
|
|
|
Try putting Text="{Binding Path=TeamDriver1, Mode=Default, UpdateSourceTrigger="LostFocus"}" to check that the update is getting triggered.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|