Другим способом, который я хотел бы сделать это, является привязка идентификатора к свойству CommandParameter кнопки:
<Button Click="Button_Click" CommandParameter="{Binding Path=ID}">View Details</Button>
Затем вы можете получить к нему доступ так же, как в коде:
private void Button_Click(object sender, RoutedEventArgs e)
{
object ID = ((Button)sender).CommandParameter;
}
System.Reflection.Assembly.GetExecutingAssembly()
.Location
1
Combine that with System.IO.Path.GetDirectoryName
if all you want is the directory.
1As per Mr.Mindor's comment:
System.Reflection.Assembly.GetExecutingAssembly().Location
returns where the executing assembly is currently located, which may or may not be where the assembly is located when not executing. In the case of shadow copying assemblies, you will get a path in a temp directory.System.Reflection.Assembly.GetExecutingAssembly().CodeBase
will return the 'permanent' path of the assembly.
Возможно, вы захотите сделать это:
System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
You can use the following code to get the current application directory.
AppDomain.CurrentDomain.BaseDirectory