PDA

View Full Version : کار نکردن رویداد کلیک یوزرکنترل WPF در windows wpf



birtemp
چهارشنبه 14 تیر 1391, 02:49 صبح
سلام.
من توی wpf یه یوزرکنترل با فرمت dll درست کردم که اونرو به فرم یه پروژه wpf اضافه می کنم. رویداد کلیک این کنترل در بین رخدادهاش موجود هست و وقتی روش دابل کلیک می کنم هم کدهای کلیک یوزر کنترل ایجاد میشن ولی وقتی کدی رو توش قرار می دم کار نمیکنه.
اینم کدهایی که من استفاده کردم.

کد xaml یوزرکنترل:

<UserControl x:Class="button1.UserControl1
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" Height="300" Width="300" Background="#FFB17C7C">
<Grid>
<Button Content="Button" Margin="10,10,12,12" Name="button1" />
</Grid>
</UserControl>

کد پشت صحنه یوزر کنترل:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace button1
{
/// <summary>
/// Interaction logic for UserControl1.xaml
/// </summary>
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}

public event EventHandler<RoutedEventArgs> Click;
}
}


کد xaml فرم برنامه:

<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" xmlns:my="clr-namespace:button1;assembly=button1">
<Grid>
<my:UserControl1 Height="300" HorizontalAlignment="Left" Margin="10,10,0,0" Name="userControl11" VerticalAlignment="Top" Width="300" Click="userControl11_Click" />
</Grid>
</Window>


کد پشت صحنه فرم برنامه:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

private void userControl11_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("DFGFDGFD");
}
}
}

ممنون میشم اگه جوابمو با کدی که قرار دادم بفرمایین.

birtemp
چهارشنبه 14 تیر 1391, 10:05 صبح
هیچ کس راضی نیست ما رو کمک کنه.
بابا ایول. دمتون گرم.

returnx
چهارشنبه 14 تیر 1391, 11:45 صبح
شما باید سوالتون رو در تالار WPF (http://barnamenevis.org/forumdisplay.php?142-WPF)بپرسید...