|
OK, Solved this ... it was a destructor on one of my classes ... will refactor ...
Jammer
<a href="http://jammer.biz/blog2/">My Blog</a> | <a href="http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=4664921">Articles</a> | <a href="http://www.jammer.biz/Projects/dmon.php">DMon</a> | <a href="http://www.jamsoft.co.uk/samplesort.php">SampleSort</a>
|
|
|
|
|
Hello,
I want to search text in a WPF richTextBox. My problem is the text is formatted...
For a normal text I use this:
string wordToSearch = "word";
TextRange tr = new TextRange(this.rtb.Document.ContentStart,
int startPos = tr.Text.IndexOf(wordToSearch);
this.rtb.Document.ContentEnd);
if (startPos > -1)
{
int l = this.GetLinesCount(tr.Text, startPosition);
TextPointer startRtb = this.rtb.Document.ContentStart;
TextPointer start = startRtb.GetPositionAtOffset(startPos + l);
TextPointer end = start.GetPositionAtOffset(wordToSearch.Length);
this.rtb.Selection.Select(start, end);
this.rtb.Selection.ApplyPropertyValue(
TextElement.BackgroundProperty,
this.rtb.SelectionBrush);
}
public int GetLinesCount(string str, int startPosition)
{
int lines = str.Take(startPosition).Count(k =>
k.Equals((char)13) || k.Equals((char)10));
return lines + 2;
}
But, for a formatted text (other color for example), I see a difference between my "word" and my "selection" of X characters.
If somebody has an idea?!?
Thank you for help me...
Bye.
|
|
|
|
|
I have defined a hyperlink in a HierarchicalDataTemplate. When the link is clicked, I want to capture it in the ViewModel.
The view is ProjectListView and its VM is ProjectListViewModel.
In my ViewModel I have:
private ICommand _SelectedLinkCommand;
public ICommand SelectedLinkCommand
{
get
{
if (_SelectedLinkCommand == null)
_SelectedLinkCommand = new RelayCommand(SelectedLinkExecuted, SelectedLinkCanExecute);
return _SelectedLinkCommand;
}
}
and
private bool SelectedLinkCanExecute()
{
return fileSelected;
}
private void SelectedLinkExecuted()
{
}
and in the XAML I have:
<HierarchicalDataTemplate DataType="{x:Type models:NodeModel}"
ItemsSource="{Binding Path=Children}">
<StackPanel Orientation="Horizontal"
Margin="2">
<TextBlock Margin="0,0,5,0">
<Hyperlink NavigateUri="{Binding Caption}"
Foreground="#0C2DAA"
Command="{Binding SelectedLinkCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={ x:Type }}}">
I copied thi code from somewhere, and I don't fully understand te FindAncestor part. What am I doing wrong here?
Everything makes sense in someone's mind
|
|
|
|
|
You can't use FindAncestor in MVVM to find the VM directly because its not in the VisualTree. You would have to put the type of your View and add a Path=DataContext.
|
|
|
|
|
Ok, I think I understand, although I don't know where the Path goes
Everything makes sense in someone's mind
|
|
|
|
|
In your command binding:
Command="{Binding Path=DataContext.SelectedLinkCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={ x:Type local:YourViewType }}}">
|
|
|
|
|
That did it . Thank you!
Everything makes sense in someone's mind
|
|
|
|
|
hi everybody
can anyone help me to know how can I rotate a usercontrol horizontally while loading??
Thanks,
|
|
|
|
|
Use a transition.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
Hi,
I have few simple controls defined in xaml in wpf.
In the code behind when I try to access this control they are coming up and also coming in VS intellisence. But during run time these controls are always null. as a result UI doesn't show.
Any reasons?
Thanks
|
|
|
|
|
are you calling InitializeComponent()?
|
|
|
|
|
yes..that is being called
|
|
|
|
|
Then run with first chance exceptions turned on. Should tell you what the problem is.
|
|
|
|
|
thanks...I have fixed...Somehow InitinitializeComponent() was not being called..
|
|
|
|
|
Hi,
Is the runat="server" attribute attached to the control?
can you post code of atleast one control?
-Manognya
__________________________________________________
$ God gives what is best.Not what all you wish
|
|
|
|
|
manognya kota wrote: Is the runat="server" attribute attached to the control?
Why would it be? He's using WPF, which doesn't have this attribute.
|
|
|
|
|
Oops!! My mistake...Thanks for the correction.dint notice its WPF
-Manognya
__________________________________________________
$ God gives what is best.Not what all you wish
|
|
|
|
|
byte[] bytBuffer = new byte[4096];
long lngBytesProcessed = 0;
long lngFileLength = fsInput.Length;
int intBytesIncurrentBlock;
CryptoStream csCryptoStream;
System.Security.Cryptography.RijndaelManaged cspRijndael = new System.Security.Cryptography.RijndaelManaged();
pbStatus.Value = 0;
pbStatus.Maximum = 100;
switch (Direction)
{
case CryptoAction.ActionEncrypt:
csCryptoStream = new CryptoStream(fsOutput, cspRijndael.CreateEncryptor(bytKey, bytIV), CryptoStreamMode.Write);
break;
case CryptoAction.ActionDecrypt:
csCryptoStream=new CryptoStream(fsOutput, cspRijndael.CreateDecryptor(bytKey, bytIV), CryptoStreamMode.Write);
break;
}
while (lngBytesProcessed<lngFileLength){
intBytesIncurrentBlock = fsInput.Read(bytBuffer, 0, 4096);
csCryptoStream.Write(bytBuffer, 0, intBytesIncurrentBlock);
lngBytesProcessed = lngBytesProcessed + long.Parse(intBytesIncurrentBlock);
pbStatus.Value = int.Parse((lngBytesProcessed/lngFileLength)*100);
}
Am getting this error with the long.Parse and int.Parse,
The best overloaded method match for 'int.Parse(string)' has some invalid arguments
The best overloaded method match for 'long.Parse(string)' has some invalid arguments
Can't convert long or int to string
plss help
|
|
|
|
|
Well, there are a few things you need to understand.
1. This forum is for WPF/Silverlight. What you posted should be dealt with in the C# forum.
2. You haven't supplied any strings to parse. The values in the Parse methods are numeric already, and Parse expects a string.
3. When parsing a string to a number, you are better off using TryParse instead - just in case the string contains crap.
4. Your post seems to indicate that you are trying to convert a long/int to a string. This can be done simply by calling ToString() on the value, or convert it with the (string) converter. Here's an example:
private string GetValue(int value)
{
return (string)value;
}
|
|
|
|
|
I am working on this dialog[^]
The part data in the center is a ListBox. I want to add radio buttons to each list row so that it will then look like this[^](I mocked this up). Each row can be always expanded an non-collapsable.
So, I have this xaml:
<Window.Resources>
<HierarchicalDataTemplate DataType="{x:Type model:PartDescriptionUpdateModel}"
ItemsSource="{Binding Path=Descriptions}">
<StackPanel Orientation="Horizontal">
<Image Source="/Abtech.Spares.UI;component/Media/Graphics/lancard_enabled_128x128.png"
Height="16"
Width="16"
Margin="0,0,3,0"/>
<TextBlock Text="{Binding Path=PartNo}"/>
<Label Content=" - "/>
<TextBlock Text="{Binding Path=Description}"/>
</StackPanel>
</HierarchicalDataTemplate>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<!--List of part info-->
<ListBox x:Name="lstParts"
Grid.Row="2"
Margin="5"
ItemsSource="{Binding PartsData}"/>
</Grid>
I am not sure how to add to the data template to get the radio buttons in there. Anyone know how to do this?
Mank thanks
Everything makes sense in someone's mind
|
|
|
|
|
In your StackPanel, you would add an ItemsControl ItemsSource={Binding SubItems} or whatever and set the item template of the ItemsControl up to be a RadioButton + Text. The tricky part here is going to be setting up the RadioButton GroupName (so the radio buttons actually behave like a group). If you have 3 radio buttons in an item, they've all got to have the same group name, but that group name has to be different for each listbox item. I'm gonna assume PartNo is unique for each part, so I'd set the group name in your ItemsControl template radio button to be PartNo.
|
|
|
|
|
Now that I think about it - there's no gaurentee that the part # will be unique in the list.
I'm wondering if I can do this more simply with a treeview.
Everything makes sense in someone's mind
|
|
|
|
|
Doesn't have to be the PartNo. That was just a suggestion that looked the simplest. You can use a GUID, or the index of the item in the ItemsSource. Anything that is unique at the ListBoxItem level. You'd run into the same issue using radio buttons in a tree. If you don't set the group name, they act like checkboxes. ItemsControl is very simple to use.
|
|
|
|
|
Ok, I understand your solution.
My data models are very simple:
public class PartDescriptionUpdateModel
{
public string PartNo { get; set; }
public string Description { get; set; }
public List<PartDescriptionModel> Descriptions { get; set; }
}
and
public class PartDescriptionModel
{
public Inventory InventoryLocation { get; set; }
public string PartDescription { get; set; }
public string ImageName { get; set; }
}
I now have this:
<Window.Resources>
<HierarchicalDataTemplate DataType="{x:Type model:PartDescriptionUpdateModel}"
ItemsSource="{Binding Path=Descriptions}">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=PartNo}"/>
<Label Content=" - "/>
<TextBlock Text="{Binding Path=Description}"/>
</StackPanel>
<ItemsControl ItemsSource="{Binding Descriptions}"
Margin="10, 0, 0, 20">
<ItemsControl.ItemTemplate>
<DataTemplate>
<RadioButton Content="{Binding PartDescription}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</HierarchicalDataTemplate>
</Window.Resources>
It produces this[^].
There are 2 problems:
1) There's only 1 radio button being displayed. There are 3 per part.
2) The same value is being displayed for all.
I'm sort of new to templating, but I'm guessing there's a binding problem? Anything look abvious to you?
Everything makes sense in someone's mind
|
|
|
|