|
Hello,
Is possible create float form as modal form in WeifenLuo.WinFormsUI.Docking and how I can do it?
I need it for moving modal float windows to right screen side as dockcontent.
Thanks
Peter
|
|
|
|
|
The best place to ask a question on a specific library is in the forums associated with the library. You might want to try posting your question here[^].
|
|
|
|
|
Hi
This is my first binding and it is not working.
It is set to TwoWay and it seems to update source data with the data from text box.
Ít doés not update the data from TextBox.
<Window.Resources>
<c:CMyData x:Key="mObj" pText="George"/>
</Window.Resources>
<DockPanel Name="dockPanel1">
<Border BorderBrush="Silver" BorderThickness="1" Name="border1" DockPanel.Dock="Top" HorizontalAlignment="Stretch" VerticalAlignment="Top" Height="50">
<Button Content="Button" Name="button1" Height="47" Click="button1_Click" />
</Border>
<Border BorderBrush="Silver" BorderThickness="1" Name="border2">
<TextBox>
<TextBox.Text>
<Binding Source="{StaticResource mObj}" Path="pText" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay" />
</TextBox.Text>
</TextBox>
</Border>
</DockPanel>
</Window>
public class CMyData : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string text="";
public string pText
{
get { return text; }
set
{
text = value;
OnPropertyChanged("CHANGED");
}
}
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
}
public partial class MainWindow : Window
{
public CMyData mObj;
public MainWindow()
{
InitializeComponent();
mObj = new CMyData();
}
private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
{
}
private void button1_Click(object sender, RoutedEventArgs e)
{
mObj.pText = "Hello\r\nWorld";
}
}
|
|
|
|
|
OnPropertyChanged("CHANGED");
... should be
OnPropertyChanged("pText");
Binding handles notification by updating the property which has been notified as changed. Or, if you want to update every property, you can notify on null.
Also, you shouldn't use name prefixes like that in .Net, particularly for public members. It should be class MyData, public string Text, etc.
And finally, the mObj you're creating in MainWindow and assigning the Text property of is not the same as the one in the resources. Instead of doing
mObj = new CMyData();
... you need to assign the local mObj (which can and should be private) out of the page resources, which I can't remember how to do off the top of my head. Hopefully a XAML/WPF expert will wander by shortly.
|
|
|
|
|
ok, I have changed the set property but I don't understand the second part.
I should not use this mObj object directly in XAML?
public string pText
{
get { return text; }
set
{
text = value;
OnPropertyChanged("pText");
}
}
mObj is declared in Window.Resources
<Window.Resources>
<c:CMyData x:Key="mObj" pText="George"/>
</Window.Resources>
I have changed the Xaml stil it is not working
<Window x:Class="binding5.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:binding5"
Title="MainWindow" Height="350" Width="525">
<DockPanel Name="dockPanel1">
<DockPanel.Resources>
<local:CMyData x:Key="mObj" pText="George"/>
</DockPanel.Resources>
<Border BorderBrush="Silver" BorderThickness="1" Name="border1" DockPanel.Dock="Top" HorizontalAlignment="Stretch" VerticalAlignment="Top" Height="50">
<Button Content="Button" Name="button1" Height="47" Click="button1_Click" />
</Border>
<Border BorderBrush="Silver" BorderThickness="1" Name="border2">
<TextBox>
<TextBox.Text>
<Binding Source="{StaticResource mObj}" Path="pText" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay" />
</TextBox.Text>
</TextBox>
</Border>
</DockPanel>
</Window>
modified 17-Jan-12 5:59am.
|
|
|
|
|
mObj is declared in the XAML, so in code, you need to retrieve the instance that's in the resources, instead of creating a new one. As I say I can't remember what the expression is exactly. It's something like mObj = Page.Resources["mObj"] but I know it isn't that simple. Someone who works with this stuff on a regular basis should come around here in a little while.
|
|
|
|
|
Thanks, realy
I have solved it:
private void button1_Click(object sender, RoutedEventArgs e)
{
CMyData mObj = (CMyData) dockPanel1.FindResource("myDataObj");
mObj.pText = "Hello\r\nWorld";
}
|
|
|
|
|
The reason this isn't working is pretty simple. You haven't actually hooked mObj in to your DataContext anywhere. All you need to do is enter the following after you initialise mObj:
DataContext = mObj;
|
|
|
|
|
but I have
<TextBox.Text>
<Binding Source="{StaticResource mObj}" Path="pText" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay" />
</TextBox.Text>
msdn:
Using the DataContext property on a parent element is useful when you are binding multiple properties to the same source. However, sometimes it may be more appropriate to specify the binding source on individual binding declarations. For the previous example, instead of using the DataContext property, you can specify the binding source by setting the Source property directly on the binding declaration of the button, as in the following example:
above
Now it works
|
|
|
|
|
But the mObj in your XAML is not the mObj in the code behind. Just because they share a name, does not mean they are the same.
|
|
|
|
|
Hello,
i am abeginer so how to start C#.
|
|
|
|
|
|
.NET Book Zero[^] is a great free introduction.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
|
hello guys...Recently I cam across a requirement in which I have to get the PK Key values back, of the inserted / updated rows. For example
<pre lang="c#">
try
{
connection.Open();
// no of rows affacted
int AffactedRows = command.ExecuteNonQuery("Some Insert Query Here", connection);
connection.Close();
MessageBox.Show(result.ToString() + " Row(s) Inserted");
}
catch(Exception ex)
{
connection.Close();
MessageBox.Show(ex.Message);
}
</pre>
Now you see <b>AffactedRows</b> contains the number of affected (or inserted) rows. Now how do I get IDs of these inserted rows? thnx for any help or pointers 
|
|
|
|
|
This almost belongs in the database forum.
It is up to your some insert query to return the value generated by the identity field. Either as an out parameter or as the return value or the selected record just inserted.
I used stored procedures that return the inserted record using the SCOPE_IDENTITY()
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
For a single row insert you can do a multipart query, like
update MyTable insert (a, b, c) values (1, 'Two', 2012-01-03); select SCOPE_IDENTITY();
... and then ExecuteScalar will return the key value added for that row.
There is a way to get the values back from a bulk insert but I can't remember what it is (I was too lazy to write the logic behind a bulk insert/update save procedure and just do a one line query for each item to be saved, considering there were only 50 or so at most in the application this was for).
Edit: SCOPE_IDENTITY is the SQL Server version, if you're using another database then you'll have to use something else, but I think they all have an equivalent query you can run.
|
|
|
|
|
I suspect my mentor is attempting to reduce me to girlie tears. I am to take my basic multiplication code and restrict the number of characters a user can enter (in order to avoid an overload)
After searching stackoverflow and Google, I can only find tutorials for textboxes but not working with console applications...or am I simply dim (stop laughing).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace debprojectC
{
class Program
{
static void Main(string[] args)
{
int number1, number2;
Console.WriteLine("Please enter a number:");
number1 = Int32.Parse(Console.ReadLine());
Console.WriteLine("Please enter another number:");
number2 = Int32.Parse(Console.ReadLine());
int result;
result = number1 * number2;
Console.WriteLine("Multiplication:" + result.ToString());
Console.ReadKey();
}
}
}
Assistance please.
Deborah
|
|
|
|
|
Instead of using Console.ReadLine you are going to have to use Console.ReadKey. Something along the lines of this:-
string str = string.Empty;
while (str.Length <= 5)
{
char c = Console.ReadKey(true).KeyChar;
if (c == '\r')
{
break;
}
if (c == '\b')
{
if (str != string.Empty)
{
str = str.Substring(0, str.Length - 1);
Console.Write("\b \b");
}
}
int enteredValue;
if(Int32.TryParse(c.ToString(), out enteredValue))
{
Console.Write(c);
str += c;
}
}
Console.WriteLine();
Console.WriteLine("You entered " + str);
Console.ReadLine();
This checks if the char entered is numeric, it handles backspaces and it checks to see if the user pressed enter. I am sure you could alter this to work with your app.
Hope it helps
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Thank you so much. This helps a great deal.
|
|
|
|
|
Glad to help
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
An alternative way to avoid the overload is just to check that the parsing actually succeeded:
bool MultiplyFromConsole(){
int number1, number2;
string line1, line2;
Console.Write("Please enter a number: ");
line1 = Console.ReadLine();
Console.Write("Please enter a number: ");
line2 = Console.ReadLine();
if(!(int.TryParse(line1, out number1) && int.TryParse(line2, out number2))
return false;
Console.WriteLine("Multiplication: " + (number1 * number2));
return true;
}
|
|
|
|
|
Thank you. My mentor wants me to allow the user another chance if he/she enters a number that is too large or enters letters instead of number. This is quite a learning experience.
Thank you for your help.
Deborah
|
|
|
|
|
hi
how to paint lines on combo-box in difference colors ?
for example:
line1 - red
line2 - green
line3 - yellow
i need any c# code
thanks
|
|
|
|
|
Throw us a bone here. What technology?
|
|
|
|